[csswg-drafts] [css-nesting] Specificity of contextually-invalid selectors. (#9600)

emilio has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-nesting] Specificity of contextually-invalid selectors. ==
Consider something like:

```html
<!doctype html>
<style>
p {
  color: green;
}

*, ::before {
  & * {
    color: red;
  }
}

:is(*, ::before) * {
  color: purple;
}
</style>
<p>Which color is this?
```

That's red in browsers, quite surprisingly, because `::before`, even though is invalid when nested (`:is(*, ::before)` or so wouldn't parse it), still contributes to specificity. `p` should win due to specificity otherwise, and the text should be green.

That seems pretty confusing? It's even more confusing when nesting `:has()` etc. But "fixing" it is actually relatively annoying.

What is the expected result here? What should be the expected result of something like nesting `:has()` inside `:has()` which suffers from the same issue? 

cc: @dshin-moz, @andruud, @tabatkins, @LeaVerou, @mdubet 

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9600 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 15 November 2023 13:28:47 UTC