[csswg-drafts] [css-values-5] Introduce nth-item() (#11103)

tabatkins has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values-5] Introduce nth-item() ==
Back in <https://github.com/w3c/csswg-drafts/issues/5009#issuecomment-626072319> I summarized the various "conditional" things we might want to add. We've now added [the `if()` function](https://drafts.csswg.org/css-values-5/#if-notation), and the big one left from that summary list is `nth-item()` (called `nth-value()` in that comment, but we should be consistent with `random-item()`'s naming).

This is a fairly trivial addition functionality-wise, and it has two good arguments for including it:

1. As argued in the thread, it gives a complementary syntax for conditionals, letting you centralize the actual condition to one spot on your page and just use it to set an integer that'll select things from the list. That way, you don't have to repeat your conditions all over your page if you have a lot of things that'll use the same set of tests.
2. If you can do `random-item()` to select a *random* item from a list, surely you should be able to do `nth-item()` to select a *non-random* item from a list, that's just something authors will expect. ^_^

Syntax would just be:

```
random-item( <integer> , [ <declaration-value>? ]# )
```

And it'll select the nth argument according to the first argument, yielding the guaranteed-invalid value if the index goes past the end of the list.

Maybe the first arg can have an optional `clamp` keyword, which would make the index clamp to the largest valid index instead of being invalid, so authors can use the final argument as the "default" value.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11103 using your GitHub account


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

Received on Monday, 28 October 2024 22:17:24 UTC