【发布时间】:2019-03-25 04:57:12
【问题描述】:
类似的问题可以在这里找到:
CSS: How to fit an image in a circle where bottom is clipped but top pops out?
但是,我希望将红色轮廓替换为图像,例如:
我尝试了 :before 和 :after 伪标签,但没有找到解决方案。我应该朝着哪个方向来实现这一目标?
【问题讨论】:
标签: html css background-image clip
类似的问题可以在这里找到:
CSS: How to fit an image in a circle where bottom is clipped but top pops out?
但是,我希望将红色轮廓替换为图像,例如:
我尝试了 :before 和 :after 伪标签,但没有找到解决方案。我应该朝着哪个方向来实现这一目标?
【问题讨论】:
标签: html css background-image clip
你可以像这样使用多个背景:
.box {
width:200px;
height:210px;
border-radius: 0 0 50% 50%/0 0 70% 70%;
background:
url(https://i.stack.imgur.com/bdZeE.png) center/cover,
url(https://i.stack.imgur.com/i7iHM.png) 0 180%/100% auto no-repeat;
position:relative;
}
.box:after {
content:"";
position:absolute;
z-index:1;
bottom:0;
top:50%;
left:0;
right:0;
background:url(https://i.stack.imgur.com/i7iHM.png) 0 90%/100% auto no-repeat;
}
<div class="box">
</div>
你也可以使用 CSS 变量控制里面的图片:
.box {
width:200px;
height:210px;
border-radius: 0 0 50% 50%/0 0 70% 70%;
background:
var(--image) center/cover,
url(https://i.stack.imgur.com/i7iHM.png) 0 180%/100% auto no-repeat;
position:relative;
display:inline-block;
}
.box:after {
content:"";
position:absolute;
z-index:1;
bottom:0;
top:50%;
left:0;
right:0;
background:url(https://i.stack.imgur.com/i7iHM.png) 0 90%/100% auto no-repeat;
}
<div class="box" style="--image:url(https://i.stack.imgur.com/bdZeE.png)">
</div>
<div class="box" style="--image:url(https://i.stack.imgur.com/7A8fP.png)">
</div>
【讨论】:
0 180%)和(0 90%)...你可以让它们0 184%和0 92%