Search code examples
csscss-selectorspseudo-elementpseudo-class

Pseudo-class on pseudo-element


OK to be clear, I am not trying to make the (pseudo)inception for css. Just wanted to check if it's possible to add a pseudo class on a pseudo element. For eg:

.some-class:after:hover {
}

doesnt seem to work.

This works though:

.some-class:hover:after {
}

And ofcourse, this doesn't:

.some-class:hover:after:hover {
 }

What I am trying to do is- there is a div. If you hover on that div, I am attaching a delete icon using :after on the div. I want to style this icon (say, have it zoom to 1.1 or so). Is this possible purely on CSS? I just need it to work on Chrome.


Solution

  • No, the current standard does not allow attaching pseudo-classes to pseudo-elements. The only place where a pseudo-element may appear is at the very end of a complex selector, and no other selectors or combinators may appear after it. Refer to the spec.

    Some implementations like WebKit have their own rules, but they are non-standard and do not work cross-browser. They may also not apply to all pseudo-classes and/or all pseudo-elements. For example, as far as I know, :after:hover does not work on any browser, Chrome included.

    Either way, you will need to use an actual element instead of a pseudo-element.