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

标签 html css css-shapes rounded-corners

我一直在尝试制作一个像这样的不均匀圆边的 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/

相关文章:

html - 脚本未被调用

javascript - 仅显示一次弹出消息

javascript - HTML5 Canvas 粒子爆炸

html - CSS 背景图片不显示在移动设备上

html - 是否可以隐藏/删除多个 div 相交区域内的边框?

html - 如何在调色板上选择一种颜色来更改图像的一部分?

html - 如何扩展一个div以匹配另一个div

jquery - 仅用于一个 div 的自定义光标图像

css - 如何使用 CSS 创建向下箭头?

html - 如何为容器添加边框,中间有透明间隙