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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)