-1

The purpose of the question is to investigate the possibility of doings something like:

.element:before {
  content: 'before';
  color: orange;
}

.element:after {
  content: 'after';
  color: green;
}

.element:after:hover + .element:before {
  color: red;
}
<div class='element'>&nbsp;</div>
BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
volna
  • 1,856
  • 4
  • 14
  • 47

1 Answers1

4

Pseudo-elements cannot be targeted by sibling combinators because sibling combinators only represent element siblings, not pseudo-element siblings.

So, although the boxes generated by ::before and ::after are siblings of one another in terms of layout, for the purposes of sibling combinators they are not.

It is not possible to write a selector styling an element's ::before pseudo-element when its ::after pseudo-element is hovered. (For that matter, ::after:hover is not valid outside of Selectors 4 either, and no implementations exist.) There are hacks that make use of things like pointer-events but there is nothing that is guaranteed to work on all browsers.

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284