我想在矩形 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 的中間添加圓呢?
uj5u.com熱心網友回復:
我通過absolute定位和::before選擇器實作了這一點。
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;
}
演示鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/388438.html
標籤:html css 推特引导 twitter-bootstrap-3 bootstrap-3
上一篇:如何將影像正確放置在父div中
