我有一個這樣的 div:
<div class="p-5 mb-3 mainInfo">
<div class="circle"><img src="https://nanoclub.ir/images/cut.png"></div>
</div>
結果是這樣的:

但是,它應該像這樣顯示在 div 中:

這是CSS:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
height:50px;
}
.circle {
position:absolute;
width:150px;
height:170px;
border-radius:50%;
background:#fff;
right:100px;
top:40%;
transform:translateY(-50%);
}
那么如何circle像預期的影像一樣將影像正確放置在div 中呢?
uj5u.com熱心網友回復:
我通過absolute定位和::before選擇器實作了這一點。我還為影像添加了最大寬度的邊框半徑。
HTML:
<div class="mainInfo">
<div class="circle">
<img src="https://picsum.photos/200" />
</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;
}
.circle img {
position: absolute;
max-width: 85%;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 200;
}
演示鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/388437.html
標籤:html css 推特引导 twitter-bootstrap-3 bootstrap-3
下一篇:如何在矩形div中添加圓形
