【问题标题】:How to add Circle shape in a rectangle div [duplicate]如何在矩形 div 中添加圆形 [重复]
【发布时间】:2022-01-22 17:44:02
【问题描述】:
我想在矩形 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 的中间添加圆圈呢?
【问题讨论】:
标签:
html
css
twitter-bootstrap
twitter-bootstrap-3
【解决方案1】:
我通过absolute 定位和::before 选择器实现了这一点。
::before 高度和背景颜色与 .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;
}
Link to the Demo