使用CSS的透明半圆切口
尽管没有带有白色圆圈的黑色矩形,但可以创建一个透明的半圆-仅使用 CSS3 的圆形切口。关键在于明智地使用 ::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); }
在这段代码中,.rect 元素表示主要形状,而 .circle 及其 ::after 伪元素一起形成了切口。 ::after 元素创建一个位于 .circle 元素后面的半圆形形状,从而产生半圆形切口的错觉。 ::after 元素的透明背景可以让背景颜色透过,达到想要的效果。
以上是如何仅使用 CSS 创建透明的半圆切口?的详细内容。更多信息请关注PHP中文网其他相关文章!