Re: [csswg-drafts] [css-syntax] Make it easier to express ranges for <An+B> selectors (#4140)

Negative numbers counting from the end of a sequence is a pretty common idiom in a number of programming languages, including JS (`[1,2,3].at(-1)`, for example).

>  but :nth-child(2n, n <= 4) means "Match the first 4 even elements".

Note that you can already write this today, with `:nth-child(-n + 4 of :nth-child(2n))`. And with the updated range syntax from Sebastain, it would be `:nth-child(n <= 4 of :nth-child(2n))`, which is fairly reasonable imo. This is how you write *every other* "I want the first 4 things matching X condition" selector; I don't think we really need a special-case form for when the condition is specifically an An+B counter.

> `:nth-child(2 <= 3n+2 <= last-3) `

I think using `last` *and* negative values is more confusion than it's worth (plus, as written, that's a single `last-3` ident). I'd prefer

```
:nth-child(2 <= 3n+2 <= last 3)
```

(I'm also fine with just using a negative number on its own, but if we go with the keyword I prefer this syntax.)

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4140#issuecomment-1622176866 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 5 July 2023 17:20:48 UTC