On nth-child, etc..

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.

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".

There is the issue of increasing the weight of the 
selector, but as Jonas pointed out, people are at least
as likely to select elements 3 through 5 as every third 
one up to 15. Selecting 3 to 5 in the current WD 
requires two selectors, as shown by Tantek Celik[2],
whereas it only requires one with the range syntax--
an even trade-off.

The range syntax also makes the relatively simple task
of selecting the first five elements easier to read. 
Compare:
  :nth-child(1..5)
  :nth-child(-n + 5)

Selectors for any sort of grouping are much easier both 
to write and maintain with the range syntax, and it 
makes even Ian Hickson's edge case[3] plausible:
  :nth-child(200n + 1..100)

~fantasai

[1] Sicking, Jonas. "css3 :nth-child() WD", www-style (2001-02-28)
 http://lists.w3.org/Archives/Public/www-style/2001Feb/0121.html

[2] Celik, Tantek. "Re: css3 :nth0-child() WD", www-style (2001-02-28)
 http://lists.w3.org/Archives/Public/www-style/2001Feb/0123.html

[3] Hickson, Ian. "Re: New version of the Selectors module of CSS3",
    www-style (2000-10-06)
 http://lists.w3.org/Archives/Public/www-style/2000Oct/0057.html

Received on Saturday, 10 March 2001 01:22:04 UTC