首页 > 解决方案 > 在 div 中添加部分背景

问题描述

我想创建一个具有部分背景的 div,例如:

在此处输入图像描述

我尝试在白色中应用边距,但我有点迷茫。

标签: htmlcss

解决方案


您没有编写任何有问题的代码。所以我现在编写示例 Html 和 CSS 代码。我希望这段代码能解决你的问题。

body{
background-color: #e3e3e3;
}
.bg-container{
background-image: url("https://i.stack.imgur.com/Q9aDy.jpg");
width:250px;
height: 250px;
background-color: #fff;
background-repeat: no-repeat;
background-size: 200px;
background-position: center center;
}
<div class="bg-container">

</div>


推荐阅读