I have a div with border-radius: 20px applied to it. The first element inside of said div is an h2 with a background color. The div's radius does not affect the h2 at all so I end up with two pointed corners sticking out of my div. I tried applying a radius to the top right and top left corners of the h2 but this left a tiny sliver of white between the div's corner and the h2's corner.
I tried decreasing the h2 border radius but to completely remove the white it ends up bulging out from the div again….
What am I doing wrong? Thank you for your help!
Here’s a jsFiddle
My CSS is essentially:
#div {
border radius: 20px;
border: 2px solid #000;
}
#h2 {
margin-top: 0px;
border-radius: 20px 20px 0 0;
}
First of all you have some typo in your code
border-radiusnotborder radiusThen, if you apply
border-radiusfor all corners for an element that have an height less thanborder-radiusitself then browser just apply the rounded corner on half of the height of the element. For example if you have adivthat have10oxheight and if you apply5pxradius for every corner then browser just applies5pxof your10pxborder-radiusto each corner. It doesn’t mean you got5pxborder-radiusit means just 5 top pixels will affect.In your sample the
divdoesn’t have enough height to accept20pxborder-radius.If you apply a
heightmore that40pxthen you can have perfectborder-radiuseffect.Look at the fiddle