11

Anyone know of a surefire way to force child elements to stay in the border-radius of their parents?

Here is a js fiddle sample I'm working with: http://jsfiddle.net/fuego/qCNRZ/

Markup:

<div id="outer">
    <div id="inner">
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
        Nah nah nah<br/>
    </div>
</div>

CSS:

#outer {
    width: 300px;
    background: red;
    border-radius:20px;

}

#inner {
    background:blue;
}

I simply want the container to appear blue now, but with the parents rounded edges. I updated the fiddle to reflect.

Fuego DeBassi
  • 2,967
  • 6
  • 29
  • 37

4 Answers4

29

Based on your example it would suffice to add overflow:hidden to your #outer element.

Daan Mortier
  • 1,868
  • 1
  • 13
  • 9
  • 3
    This is the right answer. Without this property, the border radius of a parent is not supposed to clip its children's content by default: http://stackoverflow.com/questions/8582176/should-border-radius-clip-the-content/8582304#8582304 – BoltClock Sep 27 '12 at 14:15
1

Adding "overflow: hidden;" to the outer div will solve your problem. Cheers.

Griffin
  • 11
  • 4
1

The only way to achieve what you wish with pure css is to add border-radius for both div.

#outer {
    width: 300px;
    background: red;
    border-radius:20px;
    height:400px;
}

#inner {
    background:blue;
    border-radius:20px 20px 0 0;
    padding-left:10px;
}

Demo: http://jsfiddle.net/tZ8AL/1/

Sotiris
  • 38,986
  • 11
  • 53
  • 85
-1

just needed margins set http://jsfiddle.net/jalbertbowdenii/83Xrs/2/

albert
  • 8,112
  • 3
  • 47
  • 63