CSS clip-circle an image and put another image as border

被刻印的时光 ゝ 提交于 2019-12-11 05:39:47

问题


Similair question can be found here:

CSS: How to fit an image in a circle where bottom is clipped but top pops out?

However, I would like to have the red outline replaced by an image, e.g.:

I tried among others :before and :after psuedo tags but did not find the soluition. Which direction I should look to achieve this?


回答1:


You can use multiple background like this:

.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>

You can also control the image inside using CSS variable:

.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>


来源:https://stackoverflow.com/questions/52906946/css-clip-circle-an-image-and-put-another-image-as-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!