We already know that we can select an element based on the presence of a certain child element (in Chrome/Edge 105+ and Safari 15.4+), but there are limitations.

<p>
  <strong>World</strong>!
</p>
p:has(strong) {
  background-color: aqua;
}

World!

This works well with actual elements, but it doesn't work with pseudo-elements.

p::before {
  content: "Hello";
}

p:has(::before) {
  background-color: salmon;
}

World!

According to the spec, that's because Pseudo-elements are generally excluded from :has() because many of them exist conditionally, based on the styling of their ancestors, so allowing these to be queried by :has() would introduce cycles..

For the sake of completeness, of course :has() works with pseudo-classes.

p:has(:hover) {
  background-color: salmon;
}

World!

My blog doesn't support comments yet, but you can reply via blog@matuzo.at.