This technique requires that the image is wrapped in a div because — and I'm not sure why — in Safari psuedo-elements won't seem to render for img
elements.
HTML
<div class="box"><img src="http://placehold.it/200x200/" /></div>
CSS
.box {
display:inline-block; /* Makes the wrapper flush with the image */
line-height: 0; /* Stops a gap appearing underneath image */
}
.box, .box:before {
border: 8px solid #fff;
border-radius: 16px;
position: relative;
z-index: 1;
}
.box:before {
display: block;
content: '';
position: absolute;
top: -8px;
left: -8px;
right: -8px;
bottom: -8px;
z-index: 2;
}
The :before
psuedo-element sits on top of the image with its inner curved border, essentially simulating the inner curved border on the image. It's a pretty nice workaround that achieves the curved inner border that you.
The border-width
of the wrapper and image and top
, left
, right
and bottom
positions of the :before
pseudo element needs to be half that of the border radius of the wrapper element.
http://jsfiddle.net/nvG5S/