html - 从div中切出的透明半圆

标签 html css css-shapes

我想只使用 CSS3 制作一个透明的切出的半圆形。唯一的要求是构成形状的所有元素必须是黑色或透明

不能在上面使用带有白色圆圈的黑色矩形,因为半圆必须是透明的并且让背景显示出来。

想要的形状:

rectangle with cut out half circle

最佳答案

也许可以用 CSS ::after 伪属性来做到这一点:

body {
  background: green;
}

.rect {
  height: 100px;
  width: 100px;
  background: rgba(0, 0, 0, 0.5);
  position: relative;
  margin-top: 100px;
  margin-left: 100px;
}

.circle {
  display: block;
  width: 100px;
  height: 50px;
  top: -50px;
  left: 0;
  overflow: hidden;
  position: absolute;
}

.circle::after {
  content: '';
  width: 100px;
  height: 100px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
  border-radius: 100px;
  background: rgba(0, 0, 0, 0);
  position: absolute;
  top: -100px;
  left: -40px;
  border: 40px solid rgba(0, 0, 0, 0.5);
}
<div class="rect">&nbsp;<span class="circle"></span></div>

View on JSFiddle

关于html - 从div中切出的透明半圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56621294/

相关文章:

javascript - 基于 Visibility JS Fade In 的 If 语句

javascript - 我可以/应该根据元素的数量为下拉菜单栏设置动态高度吗?

html - 使用 Wordpress-shell 并编写自定义帖子类型

javascript - 在 Jquery 中附加在 Image 的 src 属性中间

javascript - 我有一个按钮可以在表格中显示表格,但它在表格外显示表格我怎么能显示[放在表格内

CSS3 动画运行延迟动画,所有部分都有全局延迟

javascript - 如果访问 anchor 标记,则设置其父元素的样式

html - 如何使用 CSS 创建自定义形状?

三 Angular 形箭头的CSS渐变

html - 带 CSS 的半圆(边框,仅轮廓)