Home > Web Front-end > CSS Tutorial > How Can I Create a Transparent Half-Circle Cutout in a Div Using Only CSS3?

How Can I Create a Transparent Half-Circle Cutout in a Div Using Only CSS3?

DDD
Release: 2024-12-27 00:24:10
Original
218 people have browsed it

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);
}
Copy after login

HTML:

<div class="rect">
  <span class="circle"></span>
</div>
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template