Re: [csswg-drafts] [selectors][css-nesting] Move nest-containing and nest-prefixed selector definitions to Selectors (#5745)

> If & will now refer to :root instead of the current element when used in :is, :where, and :has

That is not the case. & refers to the elements matched by the parent rule's selector. If you use & in a non-nested rule, it'll be the same as :scope. It's never been given a special behavior in the `:is()`/etc explicitly. (The most recent change was just to make a non-nested `&` match `:scope`, rather than matching *nothing*.)

There was discussion a while ago about having `:scope` in `:is()`/etc refer to the element the pseudo-class was filtering, but we ended up not doing that. (It causes conflicts with other uses of `:scope`, like `@scope` or `querySelector()`, and makes implementation more difficult.)

> To make a selector list forgiving inside :has(), the general direction has been to nest an :is() inside the :has() like this: :has(:is()).

Note that just wrapping the whole selector argument in :is() has *always* not been correct if the selector contains any combinators. That is, `A:has(B C)` and `A:has(:is(B C))` aren't the same thing - both will match against `<A><B><C>`, but second will *also* match against `<B><A><C>` - it looks for a C element with a B ancestor, regardless of its relationship with A. This is because the :has() argument is a `<relative-selector>` and thus *always* contains a combinator even if you don't write one - it just defaults to the descendant combinator in that case.

You can either wrap the `:is()` around the `:has()` instead, or if you really do want to make the interior forgiving, wrap an `:is()` around the specific compound selectors you're worried about. That is, to make `.a:has(> :unknown)` forgiving, either write `.a:is(:has(> :unknown))`, or `.a:has(> :is(:unknown))`.

(If we *did* have a way of opting `:has()`'s argument out of being relative, such as by keying off the presence of some specialized selector like `:has-subject` or something, then wrapping the whole argument in `:is()` would work. 

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


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

Received on Friday, 13 January 2023 20:17:10 UTC