Last Updated: May 04, 2019
·
2.869K
· timpietrusky

Use pseudo-elements on replaced elements

If you want to use the :after or :before on replaced elements (e.g. img or input) you can use the following hack:

Enable the pseudo element for the img with an empty content property on the img itself:

img {
    content: '';
}

Add the pseudo element to the img:

img:after {
    content: 'Pseudo Content, Yeah';
}

Example

Browser Support

  • Chrome 10+
  • Firefox 11+
  • Opera 9.8+
  • Safari

Further reading

1 Response
Add your response

Nice for img elements - doesn't seem to work on inputs though (which the description led me to believe).

Nice workaround, nonetheless!

over 1 year ago ·