Solution 1
To achieve the desired effect, utilize CSS Positioning techniques. Begin by enclosing the image in a div
element and then implement the CSS pseudo :after
element with an absolute position and an inset box-shadow
Ensure that the container element, which is a div
element in this case, has been set to position: relative;
to avoid the shadow escaping uncontrollably.
View Demo
div:after {
content: "";
position: absolute;
height: 100px;
width: 100px;
border-radius: 50%;
box-shadow: inset 0 0 12px blue;
top: 0;
left: 0;
z-index: 1; /* Use higher values for priority */
}
Don't forget to apply the z-index
property to the absolute
positioned pseudo element to ensure it remains visually on top...
Additionally, note that if you want the div
s positioned side by side, use float
or display: inline-block;
as div
elements are naturally block-level and take up the full width of the document...
Updated Demo (includes z-index
usage)
Solution 2
If deemed necessary to avoid utilizing the :after
pseudo element (although compatibility exists back to IE8), consider setting a negative z-index
on the img
element and applying the box-shadow
with an inset
value directly on the div
element.
div {
margin: 10px;
float: left;
box-shadow: inset 0 0 12px blue;
border-radius: 50%;
}
div img {
display: block;
height: 100px;
width: 100px;
border-radius: 50%;
position: relative;
z-index: -1;
}
Alternate Demo (Experimenting with the z-index
property)