Home >Web Front-end >CSS Tutorial >How to Create an Inverse Circle Shape Using CSS3?
Question:
How can I create an "inverse circle" shape, where the outer edge of the container is circularly cut out, leaving a solid circle in the center?
Answer:
CSS3 Radial Background Gradient Option
(For modern browsers like Firefox, Chrome, Safari, and IE10)
This improved solution allows for a transparent "gap" between the circle and its inverse cutout:
CSS:
.inversePair { border: 1px solid black; display: inline-block; position: relative; height: 100px; text-align: center; line-height: 100px; vertical-align: middle; } #a { width: 100px; border-radius: 50px; background: grey; z-index: 1; } #b { width: 200px; padding-left: 30px; margin-left: -30px; border-left: none; border-top-right-radius: 20px; border-bottom-right-radius: 20px; background-image: -moz-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px); background-image: -webkit-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px); }
Original Answer:
<div>
.inversePair { border: 1px solid black; background: grey; display: inline-block; position: relative; height: 100px; text-align: center; line-height: 100px; vertical-align: middle; } #a { width: 100px; border-radius: 50px; } #a:before { content: ' '; left: -6px; top: -6px; position: absolute; z-index: -1; width: 112px; height: 112px; border-radius: 56px; background-color: white; } #b { width: 200px; z-index: -2; padding-left: 50px; margin-left: -55px; overflow: hidden; border-top-right-radius: 20px; border-bottom-right-radius: 20px; } #b:before { content: ' '; left: -58px; top: -7px; position: absolute; width: 114px; height: 114px; border-radius: 57px; background-color: black; }
Both solutions result in a visually pleasing "inverse circle" effect, achieving your desired shape without the need for images.
The above is the detailed content of How to Create an Inverse Circle Shape Using CSS3?. For more information, please follow other related articles on the PHP Chinese website!