Question:
How do you create a half-circle using only CSS, with a single div element and without relying on external tools like SVG or graphics APIs?
Answer:
Achieving a half-circle effect with CSS can be accomplished by leveraging border properties. To do this:
border-top-left-radius: 110px; // Height + Border border-top-right-radius: 110px; // Height + Border
border: 10px solid gray; border-bottom: 0;
This combination of rounded corners and borders creates a half-circle shape.
Example:
<code class="css">.half-circle { width: 200px; height: 100px; border-top-left-radius: 110px; border-top-right-radius: 110px; border: 10px solid gray; border-bottom: 0; }</code>
Alternative Method:
An alternative approach is to use box-sizing: border-box, which calculates the width and height of the box including borders and padding. This way, you can specify the height as exactly half of the width:
<code class="css">.half-circle { width: 200px; height: 100px; border-top-left-radius: 100px; border-top-right-radius: 100px; border: 10px solid gray; border-bottom: 0; box-sizing: border-box; }</code>
Both methods can achieve the desired half-circle effect using purely CSS techniques.
The above is the detailed content of How to Create a Half-Circle with CSS Using a Single Div?. For more information, please follow other related articles on the PHP Chinese website!