Border-radius and padding not playing nice

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.

Answers


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


Set the padding on "wrap" not on the image (setting paddings on images does not make much sense :)), that should fix your problem.


This is a byproduct of applying both padding and a border-radius to the same element in some browsers (mostly IE and safari). The border-radius changes the curvature of the border component of the box model, which surrounds the padding component.

In addition to the other answers, another interesting thing that seems to fix the issue is adding a border line. If you don't want to see the border, you could use border: 1px solid transparent, like this:

.invisible-border {
    border: 1px solid transparent;
}
Demo in jsFiddle


Had the same problem with a span instead of an img. Not exactly the same scenario since both tags have different display values (see this SO thread).

In my case, setting display:inline-block to the span fixed everything.


Need Your Help

android 4.0, text on the action bar NEVER shows

android android-4.0-ice-cream-sandwich android-actionbar

I am trying to use the new api's from google, specifically the action bar.