我一直在尝试制作一个具有不均匀圆边的 DIV,如下所示:
我检查了一些解决方案,最接近的解决方案是使用 border-radius 。我用过:
border-bottom-left-radius: 80%50px;
border-bottom-right-radius: 30%30px;
这怎么办?
代码也可以在这里找到:https://css-shape.com/rounded-edge/
clip-path
.box {
height: 200px;
width: 200px;
background: blue;
clip-path: circle(75% at 65% 10%);
}
<div class="box">
</div>
radial-gradient
.box {
height: 200px;
width: 200px;
background: radial-gradient(circle at 65% 10%, blue 75%,#0000 75.5%);
}
<div class="box">
</div>
或者使用带有
border-radius
的伪元素并依赖溢出
.box {
height: 200px;
width: 200px;
position: relative;
overflow: hidden;
}
.box:before {
content: "";
position: absolute;
inset: 0 -10% 10%;
background: blue;
border-radius: 0 0 50% 100%;
}
<div class="box">
</div>
我们不要忘记 SVG 解决方案(作为常规元素或背景)
svg {
display:inline-block;
}
.box {
display:inline-block;
height:200px;
width:200px;
background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' width='200' height='200' fill='blue'> <path d='M0 0 L0 28 C10 46 30 60 64 48 L64 0 Z' /></svg>")0 0/100% 100% no-repeat;
}
<svg
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 64 64'
width='200' height='200'
fill='blue'>
<path d='M0 0 L0 28 C10 46 30 60 64 48 L64 0 Z' />
</svg>
<div class="box">
</div>
http://jxnblk.com/paths/?d=M0 0 L0 28 C10 46 30 60 64 48 L64 0 Z
mask-image
:
.box {
height: 200px;
width: 200px;
background:blue;
-webkit-mask-image: radial-gradient(circle at 65% 10%, #fff 75%,#0000 75.5%);
mask-image: radial-gradient(circle at 65% 10%, #fff 75%,#0000 75.5%);
}
<div class="box">
</div>
这是
radial-gradient
解决方案的另一种语法,不使用 at
,Safari 不支持
.box {
height: 200px;
width: 200px;
background:
radial-gradient(blue 60.5%,#0000 61%) 35% 100%/200% 200% no-repeat;
}
<div class="box">
</div>