W3C home > Mailing lists > Public > www-style@w3.org > March 2001

On nth-child, etc..

From: fantasai <fantasai@escape.com>
Date: Sat, 10 Mar 2001 01:23:11 -0500
Message-ID: <3AA9C84F.BF28A990@escape.com>
To: www-style@w3.org
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:
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. 
  :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)


[1] Sicking, Jonas. "css3 :nth-child() WD", www-style (2001-02-28)

[2] Celik, Tantek. "Re: css3 :nth0-child() WD", www-style (2001-02-28)

[3] Hickson, Ian. "Re: New version of the Selectors module of CSS3",
    www-style (2000-10-06)
Received on Saturday, 10 March 2001 01:22:04 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:26:57 UTC