Border-radius and padding not playing nice

Curtis Cook picture Curtis Cook · Feb 23, 2012 · Viewed 19.6k times · Source

I'm having trouble trying to get a radius on images. I've simplified my problem and exaggerated the variables for demonstration purposes.

CSS:

div.wrap img {
    -moz-border-radius: 50px;
         border-radius: 50px;
}
img.pic {
    padding: 15px 25px 35px 45px;
}

HTML:

<div class="wrap">
    <img class="pic" src="http://i.imgur.com/UAef0.jpg"
         width="300" height="300" />
</div>

If I remove the padding, poof, pretty corners. If it helps, there's a reason why they're in two different classes. "wrap" can have more than one "pic" in it. Sometimes they'll be of the same class, other times they wont, sort like this:

img.left_pic  { float:left;  padding:5px 10px 5px 5px; }
img.right_pic { float:right; padding:5px 5px 5px 10px; }

Any help or insight would be appreciated.

jsFiddle: http://jsfiddle.net/NwfW6/

Edited for a solution:

This was more or less what I basically was trying to do. I think I was having a 'duh' moment. I'm sure now the declaration I needed to used was margin not padding. Another Thanx to GGJ for reminding me how to go about it the right way. And what Jan said about adding padding to an 'img' tag making no sense, It doesn't. My bad.

Answer

GGJ picture GGJ · Feb 23, 2012

Your border radius will be outside of the padding, try setting margins instead which will space outside of the border.