W3C home > Mailing lists > Public > public-css-archive@w3.org > December 2019

Re: [csswg-drafts] [css-values] Proposal: add sibling-count() and sibling-index() (#4559)

From: Tommy Hodgins via GitHub <sysbot+gh@w3.org>
Date: Thu, 05 Dec 2019 16:38:17 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-562209653-1575563896-sysbot+gh@w3.org>
I can immediately see the value of both `sibling-count()` and `sibling-index()` and other related ideas too; in the past I've applied two similar concepts to styling:

- index of this tag amongst its siblings (the children of its `parentElement`)
- index of this tag amongst the list of tags in the document matching a given selector (similar to index inside `querySelectorAll` results)

For the second idea I've [made a plugin to help](https://www.npmjs.com/package/jsincss-tag-count) in the past, though now when I want to use this concept I usually reach for CSS custom properties and a little JS for a cleaner approach. Having the awareness of a tag's index inside `parentElement.children` or `document.querySelectorAll(selector)` in CSS natively, as well as the `parentElement.children.length` and/or `el.children.length` could simplify lots of existing tricky styles that have been built in much more complex ways!

GitHub Notification of comment by tomhodgins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4559#issuecomment-562209653 using your GitHub account
Received on Thursday, 5 December 2019 16:38:19 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:57 UTC