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

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

behdad

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