Skip to content

[css-values-5] Why is sibling-count() self-including? #12062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nt1m opened this issue Apr 9, 2025 · 6 comments
Closed

[css-values-5] Why is sibling-count() self-including? #12062

nt1m opened this issue Apr 9, 2025 · 6 comments

Comments

@nt1m
Copy link
Member

nt1m commented Apr 9, 2025

I just discovered today that sibling-count() is self-including today:

The sibling-count() functional notation represents, as an <integer>, the total number of child elements in the parent of the element on which the notation is used.

I guess this might be an english language bias, but when people ask "how many siblings do you have?", you usually don't include yourself.

There might be a reason for this choice (perhaps simply avoiding 0 which is problematic in division and other calculations) but I couldn't find a previous issue about this. I'd personally find it surprising the first time I would use this function, but I could live with it.

@nt1m
Copy link
Member Author

nt1m commented Apr 9, 2025

cc @tabatkins @argyleink @weinig

@Loirooriol
Copy link
Contributor

See #4559 (comment), #4559 (comment)

@yisibl
Copy link
Contributor

yisibl commented Apr 10, 2025

I guess this might be an english language bias, but when people ask "how many siblings do you have?", you usually don't include yourself.

In the Chinese context, it usually includes myself.

@lilles
Copy link
Member

lilles commented May 5, 2025

@nt1m Did the previous discussions linked to by @Loirooriol cover your concerns, or do you want this issue to be further discussed?

@tabatkins
Copy link
Member

It's self-including because the use-cases for it all involve the total child counts. Almost any example that wants to style something based on how many children are in an element wants to know the total number, like calc(100% / sibling-count()) or something. Counting the number of children excluding the element itself is a much more niche use, and in the rare cases it is what you want, can be done with a simple - 1 in the calc().

I understand that the name sibling-count() somewhat leans toward the "excluding the element itself" meaning, but there's no better English word to use. We originally thought to name these functions similar to the selector functions, but "children" was more confusing, since it implied counting or indexing the element's children, not the set of children the element was part of. We switched to "sibling" for clarity, knowing this sort of confusion was possible, and judged it worthwhile.

(Even in English, it's a little ambiguous - if you're asked "how many siblings do you have?" I sometimes say "there's 3 of us, me and my two brothers", because people are usually actually wanting to ask how many children my parents have, but are talking to me and so are compelled to phrase the question with me as the subject.)

@nt1m
Copy link
Member Author

nt1m commented May 5, 2025

Yeah that makes sense, parent-children-count() could be a possibility but I don't think it's worth the verbosity

@nt1m nt1m closed this as completed May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants