gpt4 book ai didi

html - 如何在 div 上创建不均匀的圆边?

转载 作者:太空狗 更新时间:2023-10-29 13:22:08 24 4
gpt4 key购买 nike

我一直在尝试制作一个像这样的不均匀圆边的 DIV:

enter image description here

我检查了一些解决方案,最接近它的是使用 border-radius。我用过:

border-bottom-left-radius: 80%50px;
border-bottom-right-radius: 30%30px;

这就是我得到的: enter image description here

如何做到这一点?

最佳答案

可以考虑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的伪元素并依赖overflow

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

这是一个很好的在线工具,可以轻松调整 SVG 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 which is not supported in Safari

.box {
height: 200px;
width: 200px;
background:
radial-gradient(blue 60.5%,#0000 61%) 35% 100%/200% 200% no-repeat;
}
<div class="box">

</div>

关于html - 如何在 div 上创建不均匀的圆边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50439518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com