Re: [csswg-drafts] [selectors-4] [css-nesting-1] pseudo elements need to be clarified to correctly handle relative selectors. (#7979)

> @sesse I noticed that Chrome currently does (2). Was there a specific reason for this? Maybe I overlooked something.

I didn't do anything specific for it; it's just that ::before isn't parsed as a combinator.

So if you look as the selector `::before`, the spec (css-nesting-1) says we are to interpret these as a relative selector (since there is no `&` in it). This is the definition of a relative selector: https://csswg.sesse.net/selectors-4/#relative

More specifically: “Relative selectors begin with a combinator, with a selector representing the anchor element implied at the start of the selector. (If no combinator is present, the descendant combinator is implied.)”

These are the combinators: https://csswg.sesse.net/selectors-4/#typedef-combinator

`<combinator> = '>' | '+' | '~' | [ '|' '|' ]`

So `::before` isn't a combinator, and thus a descendant combinator is simplied, and the rule is equivalent to `& ::before`, not `&::before`. If you want some other behavior, you'll probably need to change the language to not be in terms of relative selectors. But I'm not an expert here :-)

-- 
GitHub Notification of comment by sesse
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7979#issuecomment-1298299356 using your GitHub account


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

Received on Tuesday, 1 November 2022 10:05:09 UTC