Do Rounded Borders Affect Content Visibility?
Question:
Why does the content of an element with rounded borders (border-radius) extend beyond the container's boundary?
Sample HTML and CSS:
.progressbar { height: 5px; width: 100px; border-radius: 5px; } .buffer { width: 25px; height: 5px; background: #999999; }
<div class="progressbar"> <div class="buffer"></div> </div>
Explanation:
By default, the content of a
"The default overflow for
...content is not clipped, i.e., it may be rendered outside the block box."
The CSS specification further explains that elements with rounded corner clipping will only affect background imagery, not content.
Consequences:
As a result, content elements may extend beyond the rounded corners of their container if visible overflow is used.
Resolution:
To ensure content is clipped within the container's rounded corners, an overflow other than visible (e.g., hidden, scroll, etc.) must be applied to the container. In this case, adding overflow: hidden to the .progressbar class will resolve the issue.
The above is the detailed content of Why Does Content Extend Beyond Rounded Corners?. For more information, please follow other related articles on the PHP Chinese website!