Re: [csswg-drafts] [css-selectors] Proposal for allowing selectors that depend on layout (:stuck, :snap, :on-screen, etc) (#5979)

Very clever idea, indeed this addresses most use cases! 

However, do note that this is based on the fact that compound selectors before the subject can never target the same element as the subject. This is true today, but may not be true in the future. If we start adding pseudo-classes that avoid circularity by depending on this fact, it could severely restrict the types of new combinators we can add.

For example, there have been discussions about a preceding sibling combinator possibly being implementable (i.e. the opposite of `+`, let's call it `<+` for the purposes of this discussion). This would re-introduce circularity, as you could do `.foo:stuck + .bar <+ .foo`.

Also, remember the [reference combinator](https://www.w3.org/TR/2013/WD-selectors4-20130502/#idref-combinators)? Among other things, it allowed authors to target labels of elements, i.e. `label /for/ input`. Depending on the placement of the label, you could do `input:stuck + label /for/ input` to apply the pseudo-class to the input itself. It was dropped due to lack of implementor interest, but this would prevent it and anything like it from ever happening.

We may well decide that the value these pseudo-classes add outweighs the value of combinators that could go backwards. However, it should be a conscious decision to accept that tradeoff, and we should first explore variations of this proposal that don't force us into adding this restriction.

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


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

Received on Sunday, 21 March 2021 03:31:27 UTC