html - 使用 CSS 倒圆 Angular

标签 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;
}
<div id="box">#box</div>

它给出了一些类似的形状

box with inverted scooped corners

我需要的形状是 enter image description here

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

有没有办法用纯CSS实现?

codesandbox demo

谢谢

最佳答案

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

  1. 此技术创建了一个 overflow hidden 的透明正方形。

    enter image description here

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

    enter image description here

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

    enter image description here


片段

#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%;
}
<div id="box">
  <div id="top"></div>
  #box
  <div id="bottom"></div>
</div>

关于html - 使用 CSS 倒圆 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57799896/

相关文章:

html - 同源限制阻止来自同源的字体

html - Angular Material - 如何正确设置 Angular Material 特定的仪表板网格?

CSS: flex-grow 保持垂直纵横比

html - 替换为 HTML ascii 码

html - IE6 中的下拉菜单 "blinking"

javascript - 加载 ajax 加载的 div 的 innerHtml

python - 如何使用 Python BeautifulSoup 将输出写入 html 文件

html - 换行符 <hr> 未按预期呈现

css - 为什么 IE7 隐藏我的溢出,据我所知,它包含的所有元素都将溢出设置为可见?

javascript - bootstrap scrollspy 在加载后突出显示最后一个导航链接按钮