带内曲线的盒子

Box with inside curve

我一直在尝试创建一个 'inside curved box' 但没有成功,我似乎没有在网上找到任何示例。任何人都可以帮助我仅使用 CSS 或 SVG 来复制它吗?

鉴于形状背景是纯色而页面背景不是,您可以使用伪元素和 box-shadow 具有高扩散半径来创建形状。这是一个 hackish 解决方案,但可以在大多数浏览器上使用,因为 box shadow 有很好的支持。

div{
  position: relative;
  height: 300px;
  width: 150px;
  border-radius: 12px;
  overflow: hidden;
}
div:after{
  position: absolute;
  content: '';
  height: 30px;
  bottom: -15px;
  width: 100%;
  left: 0px;
  box-shadow: 0px 0px 0px 500px blue;
  border-radius: 12px;
}

body{
  background: linear-gradient(chocolate, brown);
  height: 100vh;
}
<div class='shape'></div>


您也可以使用 SVG path 元素实现相同的效果,如下面的代码片段所示。

div {
  height: 300px;
  width: 150px;
}
svg path {
  fill: blue;
}
body {
  background: linear-gradient(chocolate, brown);
  height: 100vh;
}
<svg viewBox='0 0 150 300' height='0' width='0'>
  <defs>
    <g id='shape'>
      <path d='M0,12 A12,12 0 0,1 12,0 L138,0 A12,12 0 0,1 150,12 L150,300 A12,12 0 0,0 138,288 L12,288 A12,12 0 0,0 0,300z' id='fill' />
    </g>
  </defs>
</svg>

<div class='shape'>
  <svg viewBox='0 0 150 300' preserveAspectRatio='none' vector-effect='non-scaling-stroke'>
    <use xlink:href='#shape' />
  </svg>
</div>