【问题标题】:CSS clip-circle an image and put another image as borderCSS 裁剪一个图像并将另一个图像作为边框
【发布时间】: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


    【解决方案1】:

    你可以像这样使用多个背景:

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

    【讨论】:

    • 看起来像答案,只是底部的“污点”被稍微剪掉了。如何解决?填充/边距不能解决问题。
    • @significant 调整背景位置(0 180%)和(0 90%)...你可以让它们0 184%和0 92%
    猜你喜欢
    • 2019-10-06
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多