Home >Web Front-end >CSS Tutorial >How Can I Create a Transparent Half-Circle Cutout in a Div Using Only CSS3?
Creating a Transparent Half-Circle Cut Out in a Div
Problem Statement:
Achieving a transparent half-circle shape cutout within a div using only CSS3, with the constraint that all elements forming the shape must be either black or transparent.
Solution:
To create the desired shape, we utilize the ::after pseudo-property of CSS:
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); }
HTML:
<div class="rect"> <span class="circle"></span> </div>
This solution creates an equilateral triangle containing a circle that is squeezed upwards so that the intersection forms a half-circle shape. By setting the background properties to black or transparent, we achieve the desired effect.
The above is the detailed content of How Can I Create a Transparent Half-Circle Cutout in a Div Using Only CSS3?. For more information, please follow other related articles on the PHP Chinese website!