tags:

views:

82

answers:

1

I have a div with border-radius set to some value (let's say 10px), and a nested div that is the full width and height of its parent.

<!-- ... -->
<style type="text/css">
div.parent {
    display: block;
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 10px;
    background: #0000ff;
    overflow: hidden;
}
div.inner {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    background: #ff0000;
}
</style>
<!-- ... -->
<div class="parent">
    <div class="inner"></div>
</div>
<!-- ... -->

I noticed that the parent does not clip the child around the rounded corners, in spite of overflow being set to hidden. Another stackoverflow thread indicates that this behavior is "by design":

http://stackoverflow.com/questions/587814/how-do-i-prevent-an-image-from-overflowing-a-rounded-corner-box-with-css3

However, upon digging up the working draft for CSS3 backgrounds and borders...

http://www.w3.org/TR/css3-background/#corner-clipping

...I couldn't help but notice the following description under the "corner clipping" section:

Other effects that clip to the border or padding edge (such as ‘overflow’ other than ‘visible’) also must clip to the curve. The content of replaced elements is always trimmed to the content edge curve

So what am I missing? Is the content supposed to be clipped to the corners? Am I looking at outdated information? Am I doing it wrong?

A: 

It's not by design, there's an outstanding defect in Firefox about this. Should work OK in any WebKit browser. In Firefox you either have to add border radius to the contained element too, or use some sort of hack.

robertc
I'd love to believe that, but I'm staring at webkit right now and still seeing the problem =/ however, that's a huge relief to see that it is listed as a bug!
cdata
@cdata Interesting - if you take both the position: relative lines out of your style sheet it works correctly in Chrome 6.
robertc
Wow, that's totally true.. so the take-away is that positioning needs to be static in order for corners to clip properly? Still seems kind of funny to me......and of course, this still fails in Firefox. Thanks for the help though! I'm gonna hold out a little bit for other answers..
cdata
@cdata Yeah, seems like it, I can't find anything through Google that explains how the positioning affects the clipping, I'll try posting on the CSS3 list and see if they have any answers.
robertc
@cdata I've been asked if it's OK to add my modified version of your test page to the W3C CSS test suite, which will mean putting it under this license: http://wiki.csswg.org/test/css2.1/contribute#how-to-license-your-contribution Please let me know if you're not OK with that.
robertc
@cdata Also they want a name and an email/url so you can be properly attributed
robertc
I've contacted you via the email address posted on your website.
cdata