Possible to make a:after/before pseudo elements clickable as part of the link? Possible to make a:after/before pseudo elements clickable as part of the link? google-chrome google-chrome

Possible to make a:after/before pseudo elements clickable as part of the link?


It looks like you have discovered a bug in the browser you are using.

Based on the spec, the generated content should be treated as a child of the element it is being generated for. I created a JSFiddle to test this out, and the generated text is linked for me in most browsers (Chrome 13 being the solitary exception.) My guess is that you are testing in Chrome. This is a reproducible bug.

The workaround is to simply specify a background color on your links ... if you want to be able to use this for all links, declaring a background image (but not specifying an image, or using a transparent .gif - or as just pointed out, setting opacity to anything other than 1) works.


I've had the same problem and apparently if I set

a { vertical-align: middle; }

(thus on the link itself, not the pseudo element), it works.


I'm hoping someone has a better solution than this, but just in case not, I did come up with this horrible/crappy/hacky solution:

  a {     margin-right: 40px;  }  a:after {     content: " (" attr(href) ")";     margin-left: -40px;  }