The other day I was trying to style CSS3 border-radius to image element and I realized that Firefox doesn't display border-radius on images. Then I figured a way to work around it — wrap a span tag around with the original image as a background-image. Thanks to Darcy Clarke for the jQuery code which does the magic tag wrapping automatically.
Goal
My goal to use the CSS3 border-radius and box-shadow feature to make the image element look like the screenshot below.

Problem
The problem is none of the modern browsers display rounded corners image the way I want it. Webkit does display the rounded corners, but the inset box shadow is not supported. In Firefox, the border-radius doesn't even display at all.
The CSS Trick
The trick is very simple: wrap a span tag around the image element. Specify the original image as background-image. To hide the original image, specify opacity:0 or display:none. I find using the opacity method is a better approach because the image will remain available for copy or download.
Final Solution With jQuery
To make things easier, we can use jQuery to automatically wrap a span tag around the image.
The jQuery code below will find any element with ".rounded-img" or "rounded-img2" (in my case, it is the image element) and wrap it with a span tag. The script finds the src, width, height, and CSS class attribute of the original image and apply them as inline styling in the span tag. Then it specifies the opacity of the image to 0 to hide it.
It works with any image dimension (with or without the width and height attribute). It can also be combined with other CSS classes. No additional markup is required.

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".rounded-img, .rounded-img2").load(function() {
$(this).wrap(function(){
return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
});
$(this).css("opacity","0");
});
});
</script>
Sample Usage
I hope you will find this trick useful. For example, you can use it to style your blog's avatar or profile photos.
Credits
Thanks to Darcy Clarke for the jQuery code.



thanks for sharing code. i’ve applied it to gallery on my site.. nice one!!
[quote comment="654"]Использую, не особо переживая. Раньше прятал текст (display:none), теперь просто удвигаю за край экрана.[/quote]Поступаю аналогичным образом. Результаты с Яшей весьма положительные. Позиция в Гугле не изменилась (была и осталась первой по интересующему запросу).
Webdesignerwall very good site., I think your article was great.
thanks for it really great work…
We used an image within a span, but instead of the background image and setting zero opacity, we applied a border-radius to both. Worked well and can be printed out too: http://easierthan.blogspot.co.uk/2012/12/code-tip-2-rounded-borders-on-images-in.html
thanks for sharing rounded corners have been an issue for a long time for different browsers.
Thanks for sharing a very useful article with us.
Hello!,,,,Great trick, Nick. Good use of jQuery as an enhancement. Might clarify things a little to mention the additional css on the class that is not included inline.
Thanks,,,,,,,,,
Excellent post. I am in love with your tutorials :)
Thanks
Wow!,,This look awesome,,,Looks so very useful and helpful post,,,,,,Thanks a lot,,,,,,,,,,!
Well written and compiled blog.You just made my week! Mighty glad the post is useful for you :)
thanks for sharing this wonderful article with us.