Re: [csswg-drafts] Allow applying style rules to the container itself (especially with style querries) (#10744)

I don't think it's viable for `:container` to be a selector, because that confuses the order in which things happen.

Unlike `@scope`, the `@container` rule does not have any impact on selector matching. Containers are discovered by first matching the selectors _inside the conditional rule_, and then each matched element has to find a relevant ancestor container to query. The query – eg `style(--color: pink)` – is applied as a conditional test after selector matching is complete.

There is no way to select elements based on their styles, since selection has to happen in order to style the elements. So at the point where we would try matching `:container` elements, we don't yet know which elements are containers. And we can't find containers until we know what elements are looking for a container to query. 

But styles are resolved outside-in – parent styles have to resolve in order for inheritance on child elements – so it is possible (after selection) to make a child style conditional on a parent/ancestor style. 

This is why container queries didn't use a selector syntax in the first place.

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


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

Received on Wednesday, 28 August 2024 02:50:18 UTC