Shouldn’t the content of my container be cut off when the container has border-radius?
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>
As you can see I use border-radius on the container (.progressbar), but the content (.buffer) goes ‘outside’ the container. I’m seeing this on Google Chrome.
Is this the expected behavior?
P.S. This isn’t about how to fix it, this is about whether it should work like this.
Yes, as crazy as it sounds, it actually is. Here’s why:
The default
overflowfor<div>elements (and most other things) isvisible, and the spec says this aboutoverflow: visible:In turn, §5.3 Corner clipping in the Backgrounds and Borders module says:
The sentence that I’ve emphasized specifically mentions that the
overflowvalue of the box must be something other thanvisible(that meansauto,hidden,scrolland others) in order for the corners to clip its children.If the box is defined to have visible overflow, which like I said is the default for most visual elements, then the content is not supposed to be clipped at all. And that’s why the square corners of
.buffergo over the rounded corners of.progressbar.Consequently, the simplest way to get
.bufferto clip within.progressbar‘s rounded corners is to add anoverflow: hiddenstyle to.progressbar, as shown in this updated fiddle.