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

Re: Proposal for CSS3.5

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 3 Sep 2010 21:50:50 -0700
Message-ID: <AANLkTi=exvuXS8Dc41WLpcSNEQz8qTHYp9hJrgrttTzc@mail.gmail.com>
To: Biju <bijumaillist@gmail.com>
Cc: www-style@w3.org
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:31 GMT