热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

使用CSS倒铲的角落

如何解决《使用CSS倒铲的角落》经验,为你挑选了1个好方法。

我有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;
}
#box

形状像

我需要的形状是

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

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

codeandbox 演示

谢谢



1> DreamTeK..:

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

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

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

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


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%;
}
#box

推荐阅读
author-avatar
xc15212
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有