Re: [csswg-drafts] [css-shadow-parts][css-nesting] is & allowed after ::part() (#10788)

> (That said, there are some comments in https://github.com/w3c/csswg-drafts/issues/9702 that suggest that &::part() and ::part()& are equivalent... which feels wrong, and seems problematic as a premise for this issue.)

No, not quite. I've posted some inconsistent things about that, tho, in this very issue.

`:hover&` and `&:hover`, I argued, were identical regardless of what the `&` represented, because Nesting isn't textual substitution, it's just a simple selector (`&`) whose matching behavior is defined contextually (matching whatever elements the parent selector matched). Since simple selectors are implicitly reorderable, then `:hover&` and `&:hover` need to be identical. Notably, `::before, ::after { :hover& {...}}` is identical to `::before:hover, ::after:hover {...}`.

Mixing pseudo-elements with `&` is different, tho (and I made a wrong argument [earlier in this thread](https://github.com/w3c/csswg-drafts/issues/10788#issuecomment-2389969859) about it). You *can't* re-order across a pseudo-element boundary, so `::foo&` and `&::foo` have be different. (Effectively, pseudo-elements are a confusingly-spelled mishmash of a combinator and a simple selector, and you obviously can't reorder across a combinator.)

`&` is still a simple selector representing a contextually-defined set of elements, so `:hover { ::part& {...}}`, while potentially syntactically meaningful (representing ::part pseudo-elements that are also part of the parent match set), by definition doesn't match anything, since the parent selector didn't match any pseudo-elements, so it can't *also* match a ::part pseudo-element selector.

------

I've been turning it over in my head for a while, and I just can't see any way to define `:hover { ::part()& {...}}` to do what's "expected" without it creating a bunch of bizarre/undefined corners. So I think we should stick with the resolution as decided for now.

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


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

Received on Tuesday, 7 January 2025 23:37:19 UTC