As far as I know, this method still does not function properly on IE7/8, so unfortunately it may not address the question at hand.
However, I frequently find myself returning to this page whenever I need a reminder on how to achieve this using modern techniques, so I am saving the solution here for future reference.
To accomplish this, I have found success by nesting the img
within a container or wrapper div since img
elements do not support pseudo-classes like :after
.
<div class="container"><img src="http://placekitten.com/240/320" alt="icanhaz"></div>
Subsequently, the CSS code is used to create a pseudo-element upon hover.
.container {
position: relative;
}
.container:hover:after {
content: '';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5); /* Alternatively, images, gradients, etc can be used here */
}
For a demonstration, refer to this example