Read more

You cannot use :before or :after on img in CSS

Arne Hartherz
May 10, 2012Software engineer at makandra GmbH

Though the W3C even gives it as an example Show archive.org snapshot , no browser actually supports this CSS:

img:before {
  content: "something";
}
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Browsers will simply not render anything when doing that on images (Fun fact: It worked in an older version of Opera but got dropped).\
The same applies to the :after pseudo-element.

This makes me sad.

You can try using jQuery instead.

Posted by Arne Hartherz to makandra dev (2012-05-10 23:03)