W3C home > Mailing lists > Public > www-style@w3.org > August 2010

Re: [Selectors3] :nth-child(-negative)

From: Behdad Esfahbod <behdad@behdad.org>
Date: Wed, 18 Aug 2010 17:07:18 -0400
Message-ID: <4C6C4B86.9060808@behdad.org>
To: Christoph Päper <christoph.paeper@crissov.de>
CC: "www-style@w3.org list" <www-style@w3.org>
On 08/17/10 05:31, Christoph Päper wrote:
> Currently :nth-child(an+b) etc. only match anything if the argument, an+b, evaluates to a positive value. 
> | The :nth-child(an+b) pseudo-class notation represents 
> | an element that has an+b-1 siblings before it in the document tree, 
> | for any positive integer or zero value of n, and has a parent element. 
> In a procedural language this declarative statement became something like
>   for (n = 0; a*n+b ≤ children.count; n++)
>     if (a*n+b > 0 and child.index == a*n+b) then style
> or
>   for (i = b; i ≤ children.count; i += a)
>     if (i > 0 and child.index == i) then style

This is wrong.  Because a can be negative.  That is, b may be >
children.count, but as i increases, the a*i+b expression gets within the range.

> I assume it helps implementation optimization that authors have to resort to :nth-last-child() if they need to count from the end. If this is not the case, would it break any other use case to define :nth-child(-1) as matching the last child (and other negative values accordingly)?

As was pointed out already, you can't do that without breaking stuff.  What I
can suggest though would be to add syntax like :nth-child(last[-+]an[-+]b) to
do what :nth-last-child() does right now.  For example: :nth-child(last) or
:nth-child(last-2n).  That is, "last" is a number that adds to the an+b

Received on Wednesday, 18 August 2010 21:08:00 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:37 UTC