如何在矩形中添加圆形 div
How to add Circle shape in a rectangle div
我想在矩形中间添加一个圆形 div 像这样:
这里是 html:
<div class="p-5 mb-3 mainInfo"></div>
然后 CSS:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
}
这就是矩形 div 的样子:
那么我怎样才能在这个 div 的中间添加圆圈呢?
我通过 absolute
定位和 ::before
选择器实现了这一点。
::before height and background color 与 .mainInfo 容器相同,它使圆形阴影隐藏在容器内。
HTML:
<div class="mainInfo">
<div class="circle">
</div>
</div>
CSS:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
width:100%;
height:5em;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
margin-top: 3em;
display: flex;
align-items: center;
justify-content: center;
}
.circle {
position: relative;
width: 8em;
height: 8em;
background: #fff;
border-radius: 50%;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}
.circle:before{
position: absolute;
content: "";
width: 15em;
height: 5em;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
z-index: 100;
}
我想在矩形中间添加一个圆形 div 像这样:
这里是 html:
<div class="p-5 mb-3 mainInfo"></div>
然后 CSS:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
}
这就是矩形 div 的样子:
那么我怎样才能在这个 div 的中间添加圆圈呢?
我通过 absolute
定位和 ::before
选择器实现了这一点。
::before height and background color 与 .mainInfo 容器相同,它使圆形阴影隐藏在容器内。
HTML:
<div class="mainInfo">
<div class="circle">
</div>
</div>
CSS:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
width:100%;
height:5em;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
margin-top: 3em;
display: flex;
align-items: center;
justify-content: center;
}
.circle {
position: relative;
width: 8em;
height: 8em;
background: #fff;
border-radius: 50%;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}
.circle:before{
position: absolute;
content: "";
width: 15em;
height: 5em;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
z-index: 100;
}