简体   繁体   English

带有边框半径的css图像

[英]css image with border-radius

I am trying to replicate this style, which has a background image, on the other hand I have a div over it that has a right border-radius, I can't do it, I provided the following options adapting them, but I couldn't我正在尝试复制这种具有背景图像的样式,另一方面,我在它上面有一个具有正确边框半径的 div,我做不到,我提供了以下选项来适应它们,但我不能't

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%);
}

The cut out example with the circle suits fine, You just need to play around with the values in the DevTools/Inspector.带有圆圈的裁剪示例很适合,您只需要在 DevTools/Inspector 中使用这些值即可。 Adjust heights/widths of the :before to stretch the curve to your liking or even mess with % of border radius, then the border width for how much space around it, the top and left to position it to the edges, then use the parent container to trim off right and bottom areas.调整:before高度/宽度以根据自己的喜好拉伸曲线,甚至弄乱边框半径的百分比,然后调整边框宽度以表示周围有多少空间, topleft将其定位到边缘,然后使用父级容器修剪右侧和底部区域。

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

you can do this by clip-path property ..你可以通过clip-path属性来做到这一点..

Note : minimum width required otherwise shape will not display注意:需要最小宽度,否则形状将不会显示

 *{ 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM