Re: Proposal for CSS3.5

On Fri, Sep 3, 2010 at 7:54 PM, Biju <bijumaillist@gmail.com> wrote:
> On Fri, Sep 3, 2010 at 6:30 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
>> Right, 1-numbering is probably better, and is more consistent with
>> current usage.  (The one place in CSS where you reference elements of
>> a list by number is :nth-child and friends, where the first element
>> has the index 1.)
>
> from http://www.w3.org/TR/css3-selectors/#structural-pseudos
>
> tr:nth-child(2n+1) /* represents every odd row of an HTML table */
> tr:nth-child(2n+0) /* represents every even row of an HTML table */
> p:nth-child(4n+1) { color: navy; }
> p:nth-child(4n+2) { color: green; }
>
> the important thing here is the "nth", where value of "n" starts with n=0
>
> So all the place in CSS we see things start with 0.

You're reading that incorrectly.  Yes, n assumes the value 0 and every
positive integer.  But the first child of an element is number 1.  Try
it out - make a few elements, and then use :nth-child(1) and
:nth-child(0).  The former will match the first element, the latter
will match nothing.

n just starts from 0 so that expressions like 2n+1 select everything
you'd expect.  If n started from 1, then the first value of 2n+1 would
be *3*.

~TJ

Received on Saturday, 4 September 2010 04:51:46 UTC