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

The syntax in Tab's comment should also include the `:nth-child(6 <= n <= 15)` from the example.

To summarize the desugarings of the breakout proposal into the existing syntax:

```css
:nth-child(n >= k of S) = :nth-child(n + k of S)
:nth-child(n > k of S) = :nth-child(n + (k+1) of S)
:nth-child(n <= k of S) = :nth-child(-n + k of S)
:nth-child(n < k of S) = :nth-child(-n + (k-1) of S)
:nth-child(k1 <= n <= k2 of S) = :nth-child(n + k1 of S):nth-child(-n + k2 of S)
:nth-child(k1 < n <= k2 of S) = :nth-child(n + (k1+1) of S):nth-child(-n + k2 of S)
:nth-child(k1 <= n < k2 of S) = :nth-child(n + k1 of S):nth-child(-n + (k2-1) of S)
:nth-child(k1 < n < k2 of S) = :nth-child(n + (k1+1) of S):nth-child(-n + (k2-1) of S)
```

Sebastian's proposal can be desugared into this proposal as such:

```css
:nth-child(k1 <= An+B <= k2 of S) = :nth-child(k1 <= n <= k2 of S):nth-child(An+B of S)
:nth-child(k1 <= An+B <= last k2 of S) = :nth-child(k1 <= n of S):nth-last-child(n <= k2 of S):nth-child(An+B of S)
```

And for my proposal it's less straightforward in general, if I didn't make a mistake,

```css
If A*k1+B >= 1,
    :nth-child(An+B, k1 <= n <= k2, of S) = :nth-child(n <= (k2-k1+1) of :nth-child(An + (A*k1+B) of S))

Otherwise,
    :nth-child(An+B, k1 <= n <= k2, of S) = :nth-child(n <= (k2+ceil(B/A)) of :nth-child(An + (A*k1+B) of S))
```

but as Tab said, the typical case of just wanting to limit the number of selected elements is simply

```css
:nth-child(n <= k of :nth-child(An + B of S))
```

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


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

Received on Monday, 24 July 2023 20:47:06 UTC