- From: Brandon McConnell via GitHub <noreply@w3.org>
- Date: Thu, 18 Dec 2025 22:29:33 +0000
- To: public-css-archive@w3.org
@tabatkins, my guess is that @kizu's intent in that example was that the relevant `ul` elements would be more than one level deeper in the DOM than the selector using `descendant-count()`, so `descendant-count()` is necessary to match those deeper elements.
For example:
```html
<section class="card">
<div class="content">
<ul></ul>
<ul></ul>
</div>
</section>
```
```postcss
.card {
/* count grandchildren <ul> elements */
--ul-count: descendant-count(> * > ul);
/* e.g. use that value to determine the necessary static height */
height: calc(200px + (var(--ul-count) * 40px));
}
```
I definitely see the value in having `children-count()` as well (https://github.com/w3c/csswg-drafts/issues/11068) since it's simpler for most common use cases where developers simply need the count of immediate children, though the semantic differences would be minor between the two (`children-count()` same as `descendant-count(> *)`)
In this example I've included above, if I know there won't be other `ul` elements within the element I'm using `descendant-count()` on, I could just as easily use `descendant-count(ul)` rather than `descendant-count(> * > ul)`, but the extra specificity here makes this much more powerful.
@kizu, please correct me if any of this is wrong. Thanks.
--
GitHub Notification of comment by brandonmcconnell
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11069#issuecomment-3672516861 using your GitHub account
--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Thursday, 18 December 2025 22:29:34 UTC