As CSS3 is hitting the web hard, rounded stuff is poppin’ up all over the place. Rounded avatars/images are starting to become a reality. Trent Walton has a nice article on this here. It’s pretty simple, just apply a border radius to the <img> itself, however Firefox and Opera don’t play well with the border-radius like other browsers do.

I want a solution for Firefox and Opera. As of now, I’ve not come up with a solution that is truly a mask (meaning it would work well on backgrounds of any color/pattern/texture, but this solution works for Opera, Firefox, Webkit and Chrome on solid color backgrounds.

Markup

<span class="frame">
<img src="/path/to/img.png" />
</span>

CSS

.frame{
display:inline-block;
position:relative;
overflow:hidden;
}
.frame>img{
vertical-align:top;
}
.frame, .frame:before{
-moz-border-radius:100em;
border-radius:100em;
}
.frame>img{
-webkit-border-radius:100em;
}
.frame:before{
content:'';
display:block;
position:absolute;
left:0;
right:0;
width:100%;
height:100%;
margin:-10em;
border:10em solid #1a1a1a;
}

Preview

Cons

The biggest con to this technique is that the rounding technique is just a color, not a mask, meaning this works well for solid backgrounds, but not patterned backgrounds :(

Play with it!

Wanna mess with the code? Go edit it live on JS Fiddle!

Comments

10 Comments

  1. karl said 954 days ago

    Tested with Opera 10.63. Works like a charm, and the same with Firefox 4.0b6

  2. Rogie said 954 days ago

    Thanks Karl!

  3. Alexander said 949 days ago

    You simple could do this in photoshop, it saves space, and all that css is not really needed.

    But it is a very nice technique!

    I personally should this in photoshop, and not in css.

  4. shyju said 930 days ago

    Now the border color is black, how can i change into white color.

  5. bowo hadi Wibowo said 906 days ago

    nice css

  6. Prakash said 896 days ago

    Excellent post of beautiful images & avatars with the proper codings. Gonna check it out.

    Thx for sharing this. Will make use of it soon.

  7. UniongeReenue said 869 days ago

    hello , cool blogue you have here!

  8. Paradox said 865 days ago

    You can actually accomplish exactly what you want, through a bit of simple jQuery.

    I’ve created a fiddle: http://jsfiddle.net/UENVQ/

    Basically, you just wrap the image in an element, and use jQuery to parse out the image’s properties (dimensions, source) and set them as css properties on the element (width, height, background).

    Once its rendered via background, you can do whatever you want. Add shadows, radii, inset shadows, borders, etc.

  9. Martin said 662 days ago

    I’ve had that twice already and I’m still only 17 minutes in

  10. Gail Hashaway said 626 days ago

    I’m a very long time watcher and I just assumed I’d drop by and say hi for that first time. I truly like your posts. Thanks

Sorry, the comment form is closed at this time.