Re: On nth-child, etc..

fantasai wrote
> I am arguing for
>   - the removal of :nth-last-child etc., with negative
>     values taking its place
>   - the adoption of Jonas Sicking's range proposal[1]
>
> As this has been sent well after the March 1st deadline,
> it is an *unofficial* comment.
> I just figured it would be of more use on www-style than
> swimming around in my head.
>
>
> IMO, :nth-last child is an unnecessary pseudo-class; it
> increases the spec without adding to it, and it only
> means more for CSS coders to memorize and implementors
> to implement. Allowing negative vlues to mean "count from
> the end" can easily replace its functionality.

I totally agree with you, I first saw using negative indexnumbers in perl
and have loved the syntax ever since. However it dosn't really fit nicly
with the an+b synax, though it surly could be done. The following syntax
could be used:
:nth-child(-1..10)  /* ten last children */
:nth-child(-3n-1)  /* same as 3n+1 (1,4,7...) but count from behind */
:nth-child(-3n+1)  /* same as 3n-1 (2,5,8...) but count from behind */

so counting would be done from behind if the *first* number is negative.
Unfortunatly the last two rules aren't very intuitive (but IMHO more logical
then the current meaning of -3n+1).

You could also allow signs on the c constant which would also allow
selectors like

:nth-child(5..-5) /* fifth child to fifth last child */

which the currently has to be done using either :not() or several rules
"undoing" each other. However, what would a rule like :nth-child(-3n-1..10)
mean?

> Negatives are logical because
>   a) The negative sign means "the opposite of"
>      Applied to indexing: the opposite of first
>      is last. The opposite of second is second
>      from the end.
>   b) Other languages have already set a precedent
>      for this use of negative parameters.
>
> The only thing :nth-last-child allows that is not
> addressed by negative values is the ability to restrict
> the upper bound of the increment, as in
>   :nth-child(-3n + 15)
>
> However, this is IMO more intuitively addressed by
> using the range proposition in a second selector:
>   :nth-child(3n):nth-child(1..15)
> Very few people would start at the fifteenth element
> and count backwards by threes. They're more likely to
> start at 3 and count by threes until 15; they're more
> likely to express their intent as "every third element
> out of the first 15".

I couldn't agree more.

/ Jonas Sicking

Received on Saturday, 10 March 2001 11:07:04 UTC