by digging · 3y ago · 0 comments
The example uses (n + 3) in a list of five items. Start counting from the 3rd item - ok, the visualization[1] shows us counting from the 3rd-from-last, so now I'm already confused. And then we count "until the end", which actually shows us counting back toward the beginning[2]. And we end up with 3 items. Are they the last 3? The first 3? I can't tell. The author should have chosen a number that didn't sit at the halfway point of the total number of items.
The description makes it sound like we start at 5 -> 4 -> 3, then select 3 items, so we select 3 -> 4 -> 5. But that's a tautology. I think what it means is that we start at 1 -> 2 -> 3, and select 3 -> 4 -> 5... is that correct?
[1] https://ishadeed.com/assets/css-has-nth-last-child/nth-last-... [2] https://ishadeed.com/assets/css-has-nth-last-child/nth-last-...
The very first demo in the MDN doc for :nth-last-child helped me understand: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-c... – just change the "-n + 3" to "n + 3" to match the example in the article.
In that case the selector starts at the third element from the bottom and ends at the top element, matching a total of 6 elements.
I still think the functional formatting is confusing. It makes sense, the pattern applies to every "A*n + B"th index (counting from the end) where n is every integer from 0..inf. But in my mind I'm just providing an offset and a step size/direction: (offset=B, step=A) or just (B A). I'd be interested to know why it's the way it is.