Is there a way to use the :before
selector in CSS to overlay an image on top of another image? I have tried implementing it, but it seems that placing an image before an img
element doesn't work as expected. Here is the CSS code I am using:
.container
{
position: relative;
display: block;
}
.overlay:before
{
content: url(images/[someimage].png);
position: absolute;
left:-20px;
top: -20px;
}
I have found that this code works when implemented like this:
<a href="[url]" class="container">
<span class="overlay"/>
<img width="200" src="[url]"/>
</a>
However, if I try to implement it like this, it does not work:
<a href="[url]" class="container">
<img width="200" src="[url]" class="overlay"/>
</a>
When I use a div
or p
element instead of the span
, the browser successfully overlays the image over the img
element. But applying the overlay class directly to the img
itself does not work.
I want to make this work without having to add an extra span
element between the a
and img
elements. It would save me a lot of time since I have many blog posts to update and modifying the stylesheet would be much more efficient than adding additional elements manually.