使用CSS倒铲的角落

RED*_*SAD 1 html css

我有CSS代码

#box {
  width: 200px;
  height: 50px;
  background-color: blue;
  border-top-left-radius: 9999px;
  border-bottom-left-radius: 9999px;
  position: relative;
  margin: 30px;
  text-align: center;
  color: white;
  padding-top: 10px;
}

#box::before,
#box::after {
  content: "";
  width: 0;
  height: 0;
  right: 0;
  position: absolute;
}

#box::before {
  border-right: 10px solid blue;
  border-top: 10px solid blue;
  border-left: 10px solid transparent;
  border-bottom: 10px solid transparent;
  bottom: -20px;
}

#box::after {
  border-right: 10px solid blue;
  border-top: 10px solid transparent;
  border-left: 10px solid transparent;
  border-bottom: 10px solid blue;
  position: absolute;
  top: -20px;
}
Run Code Online (Sandbox Code Playgroud)
<div id="box">#box</div>
Run Code Online (Sandbox Code Playgroud)

形状像

倒角勺盒

我需要的形状是 在此处输入图片说明

我需要曲线,而不是如图中右上角(#box::before)和右下角()的三角形中的斜边#box::after

有什么方法可以实现使用纯CSS?

codeandbox 演示

谢谢

Dre*_*TeK 5

您可以使用box-shadow属性创建凹面半径。

  1. 此技术创建一个透明的正方形,其中隐藏了溢出。

    在此处输入图片说明

  2. 然后,它会创建一个带有框阴影的透明圆。

    在此处输入图片说明

  3. 然后,我们将圆的位置调整为仅查看圆的四分之一。

    在此处输入图片说明


SNIPPET

#box {
  position: relative;
  width: 200px;
  height: 50px;
  background-color: blue;
  border-radius: 9999px 0 0 9999px;
  margin: 30px;
  text-align: center;
  color: #fff;
  padding-top: 10px;
}

#top,
#bottom {
  position: absolute;
  height: 30px;
  width: 30px;
  right: 0;
  overflow: hidden;
}

#top {
  top: -30px;
}

#bottom {
  bottom: -30px;
}

#top::before,
#bottom::before {
  content: '';
  position: absolute;
  right: 0;
  height: 200%;
  width: 200%;
  border-radius: 100%;
  box-shadow: 10px 10px 5px 100px blue;
  z-index: -1;
}

#top::before {
  top: -100%;
}
Run Code Online (Sandbox Code Playgroud)
<div id="box">
  <div id="top"></div>
  #box
  <div id="bottom"></div>
</div>
Run Code Online (Sandbox Code Playgroud)