46

I'd like to apply two css ::after pseudo-elements to a single DOM element, each with a different colour. (Yes, I could wrap the DOM element in another DOM element and give each one and ::after pseudo-element, but my preference is cleaner html.)

I doubt it's possible, but wonder if someone can tell me better.

I especially doubt the possibility of chaining ::after pseudo-elements together so that one ::after pertains to another, which pertains to a DOM element, but if anyone knows how to make that happen, please do tell.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
JellicleCat
  • 28,480
  • 24
  • 109
  • 162

3 Answers3

44

You can use a :before pseudo-element in addition to your :after - http://jsfiddle.net/BePSq/

Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
11

You can't add two ::after pseudo-elements to one DOM element. You can however add an ::before additionally. Depending on what you are trying to accomplish, this may work.

bookcasey
  • 39,223
  • 13
  • 77
  • 94
3

You can use both the :before and :after pseudo-elements simultaneously on one DOM element. Just make sure you position them correctly. I believe :before places the psudo-element before the parent one, while :after places it after in the html. You can only use these two however and cannot add more pseudo-elements than that.

David
  • 31
  • 1
  • They're effectively both child elements of the parent element, with `::before` appearing before the element content, and `::after` coming last. – Conan Jan 22 '17 at 11:07