Re: [csswg-drafts] [selectors-4] New selector based on the amount of child elements (#5694)

Yeah, I agree this is not so complicated as `:has()` because it doesn't descend. However, it's still a bunch of work and cache misses to walk the DOM if there are tons of children, so that's still not great and probably would need similar caches to what `:nth-child` and co have. [Gecko does keep track of the child count](https://searchfox.org/mozilla-central/rev/c938c7416c633639a5c8ce4412be586eefb48005/dom/base/nsINode.h#2208)), but that includes text-nodes (: 

Two things that come to mind:

 * I suspect this is usually not what you want? I suspect you generally want number of _rendered_ elements, which is a lot harder to compute (and define, more generally). Though you could argue that `:nth-child()` has the same issue.
 * Shadow DOM makes this all a bit more useless (and it wasn't around when `:nth-child()` and friends came to be). Again, might not be a blocker either, we have tons of other tree-abiding selectors.

Is there any chance you could elaborate of what particular styling changes you'd apply based on the number of child elements? The thing I can think of is stuff like changing the width of the parent based on number or such, but that seems brittle / repetitive and better suited by stuff like flex / grid / tables / inline-block etc...

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


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

Received on Wednesday, 4 November 2020 19:36:47 UTC