【问题标题】:css image with border-radius带有边框半径的 css 图像
【发布时间】:2020-09-16 02:20:58
【问题描述】:

我正在尝试复制这种具有背景图像的样式,另一方面,我有一个具有正确边框半径的 div,我做不到,我提供了以下选项来调整它们,但我做不到

enter image description here

Transparent hollow or cut out circle

div{
    position:relative;
    width:500px; height:200px;
    margin:0 auto;
    overflow:hidden;
}
div:after{
    content:'';
    position:absolute;
    left:175px; top:25px;
    border-radius:100%;
    width:150px; height:150px;
    box-shadow: 0px 0px 0px 2000px #E3DFD2;
}

body{background: url('https://farm9.staticflickr.com/8760/17195790401_ceeeafcddb_o.jpg';

Background with radius-top inside

div {
    background:lightgreen;
    width:100%;
    height:200px;
    position:relative;
    text-align:center;
    padding:100px 0 0 0;
    box-sizing:border-box;
}
div:before {
    content:'';
    position:absolute;
    background:white;
    width:100%;
    height:100px;
    top:0;
    left:0;
    border-radius:40%;
    transform:translatey(-50%);
}

【问题讨论】:

    标签: html css image sass


    【解决方案1】:

    带有圆圈的裁剪示例非常适合,您只需要使用 DevTools/Inspector 中的值。 调整:before 的高度/宽度以将曲线拉伸到您喜欢的程度,甚至弄乱边框半径的百分比,然后调整边框宽度以显示它周围的空间,top 和left 将其定位到边缘,然后使用父容器修剪掉右侧和底部区域。

    .banner {
      background: url(https://farm9.staticflickr.com/8760/17195790401_ceeeafcddb_o.jpg);
      background-size: cover;
    }
    
    .shape {
      position: relative;
      width: 170px;
      height: 440px;
      overflow: hidden;
    }
    
    .shape:after {
      content: '';
      position: absolute;
      left: -100px;
      top: -200px;
      border-radius: 100%;
      width: 151px;
      height: 440px;
      border: 200px solid #ffffff;
    }
    <div class="banner">
      <div class="shape">
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      您可以通过clip-path 属性来做到这一点..

      注意:需要最小宽度,否则形状将不会显示

      *{
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }
      .container {
      width: 100%;
      margin: 0 auto;
      display: flex;
      }
      .left{
        width: 10%;
      }
      
      .image {
        width: 90%;
        height: 400px;
        overflow: hidden;
        background: url(https://farm9.staticflickr.com/8760/17195790401_ceeeafcddb_o.jpg);
        background-size: cover;
        clip-path: circle(100% at 100% 50%);
      
      }
      <div class="container">
        <div class="left">
        </div>
        <div class="image">
        </div>
      </div>

      【讨论】:

        猜你喜欢
        • 2020-09-15
        • 1970-01-01
        • 2013-06-10
        • 1970-01-01
        • 2019-03-19
        • 2013-09-06
        • 2012-02-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多