Timeline for Why does :nth-child() in CSS start from 1 instead of 0?
Current License: CC BY-SA 4.0
25 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
S Dec 30, 2022 at 15:40 | history | suggested | Pang | CC BY-SA 4.0 |
Minor improvements.
|
Dec 30, 2022 at 2:41 | review | Suggested edits | |||
S Dec 30, 2022 at 15:40 | |||||
Mar 9, 2022 at 2:33 | comment | added | Marshall Davis | One of the best answers I've read in terms of readbility to coverage depth ratio. | |
Mar 8, 2022 at 22:55 | comment | added | Felype | 0-indexing makes array arithmetics easier requiring less "minus 1" and parenthesis when doing modulo operations | |
Mar 2, 2022 at 16:29 | comment | added | JacquesB | @AaronRasmussen: You should distinguish between ordinal numbers and cardinal numbers. Ordinal numbers are used to identify distinct elements by position, while cardinal numbers are used for amounts. It is the difference between "the third paragraph" and "three paragraphs". You can have zero children but you can't say "my zeroth child". | |
Feb 23, 2022 at 17:12 | history | edited | JacquesB | CC BY-SA 4.0 |
added 630 characters in body
|
Apr 3, 2016 at 8:37 | comment | added | gnat | @scriptin one can argue that absence of variables supports the assumption that language is intended for non-programmers. "Let's spare users from the need to learn yet another programming related thing" | |
Apr 3, 2016 at 8:27 | comment | added | JacquesB |
@gnat: The method you quote use 0-based indexing, but the term "zeroth child" is not used. In the DOM, child nodes are also indexed from 0, but the method to get the item at index 0 is called firstChild() , not zerothChild() . So ordinal numbers start from 1st even in the case of 0-based indexing.
|
|
Apr 2, 2016 at 20:52 | comment | added | Aaron Rasmussen | I don't disagree with your answer, but many things that we count don't start at 1. You are 0 years old for the first year of your life - you don't start out at 1. The day doesn't start at 1:00 a.m. - it starts at 0:00 a.m. When I measure the distance traveled from my house, I start at zero. Counting from zero is just as natural for human beings as counting from one - it depends on the context, although you are right that we would never speak of our zeroeth child :) | |
Apr 2, 2016 at 18:27 | history | edited | JacquesB | CC BY-SA 3.0 |
added 66 characters in body
|
Apr 2, 2016 at 18:17 | comment | added | JacquesB | @scriptin: "intended for use by non-programmers" does not necessary mean easy to use. It just mean you don't expect the audience to have experience with computer science or general purpose programming languages. They might still require highly specific domain expertise. Some of the problems CSS tackle are intrinsically complex. | |
Apr 2, 2016 at 17:50 | comment | added | JacquesB | @scriptin: I just meant CSS is a domain-specfic language designed for a certain audience of designers and web-developers. Some of these may also be programmer, but programmers are only a subset of the audience. That does not mean CSS is necessarily accessible to anyone, e.g. it uses a number of technical terms from typography and design which a programmer without any design background would probably not understand. But any competent web designer would understand a RGB code. | |
Apr 2, 2016 at 17:03 | comment | added | scriptin |
@JacquesB "CSS is designed for humans" - well... if it was, it would have variables, so I could name my #b64d27 a link-color-normal or something. CSS is just a way to create a bunch of rules which fight each other with their specificity, ending up in adding !important to all the things. Yeah, that old "intended for use by non-programmers" hairy-tail.
|
|
Apr 2, 2016 at 16:47 | history | edited | JacquesB | CC BY-SA 3.0 |
added 11 characters in body
|
Apr 2, 2016 at 16:44 | comment | added | JacquesB | @0fnt: Apparently it is not common knowledge for everyone, judging by other comments. | |
Apr 2, 2016 at 16:31 | comment | added | 0fnt | Can you delete everything except the last paragraph? Everything else is common knowledge on this SE. "While most programmers ...... natural to choose 1-based indexing" | |
Apr 2, 2016 at 15:51 | history | edited | JacquesB | CC BY-SA 3.0 |
added 341 characters in body
|
Apr 2, 2016 at 15:40 | comment | added | gnat | @SamiKuhmonen javax.swing.tree.TreeModel.getChild(Object parent, int index) "...index is a valid index for parent (that is index >= 0 && index < getChildCount(parent))" | |
Apr 2, 2016 at 15:33 | history | edited | JacquesB | CC BY-SA 3.0 |
added 341 characters in body
|
Apr 2, 2016 at 15:22 | comment | added | Sami Kuhmonen | @gnat Is there anywhere in programming any item where a child is said to be the zeroth? Since the selector is nth-child its logical to start from first. | |
Apr 2, 2016 at 15:16 | history | edited | JacquesB | CC BY-SA 3.0 |
added 341 characters in body
|
Apr 2, 2016 at 10:48 | comment | added | gnat | it would help if your answer mention that you believe CSS is primarily intended for use by non-programmers (preferably backed up somehow) | |
Apr 2, 2016 at 10:45 | comment | added | JacquesB | @gnat: Would you say my comment here is the first in the thread - because yours is the zeroeth? Humans don't count like that, and CSS is designed for humans, not computer scientists :) | |
Apr 2, 2016 at 10:28 | comment | added | gnat | "Why numbering should start at zero" | |
Apr 2, 2016 at 10:22 | history | answered | JacquesB | CC BY-SA 3.0 |