Re: [css3-selectors] structural child indexes vs rule selections

Mike Wilson wrote:
> Pardon me if this have been covered before, but has there been
> any discussion on whether :nth-child (and other structural 
> selectors) should be able to work on indexes from the selected
> child subset rather than from the 'complete' child list?

I don't think there is, but note that the :first-child and :last-child 
pseudo-classes don't do so either.

> Would it be desirable to instead count indexes based on 
> the selected subset, like in:
>   li.item:nth-child(odd) {background-color:grey;}
>   <li>...</li>             --> (not selected)
>   <li class="item">a</li>  --> index 1 = odd = grey
>   <li class="item">b</li>  --> index 2 = even
>   <li class="item">c</li>  --> index 3 = odd = grey
> ?

Some thoughts off the top of my head:

1)  I can see some use cases for that, but under a different name,
     since the existing nth-child is pretty interoprably implemented
     already; changing behavior at this point would involve changing
     a bunch of selector engines, changing web pages that depend on
     the current behavior (which has been specified for a while), and
     so forth.  Not the sort of change one makes in Last Call, in my
2)  How does one define what the "selected subset" is?  Are we talking
     about "children of the same parent that match the rest of the
     selectors in this rule" or something along those lines?  If so, how
     does this work when multiple :nth-child or :nth-of-type selectors
     are present?  It basically seems like this significantly complicates
     the existing "each chain of simple selectors matches the
     intersection of the sets of nodes the individual simple selectors
     match" model CSS has right now.
3)  No matter how it's defined, matching will of course be slower than
     for :nth-child.  We have some of this problem already for
     :nth-of-type so it might not be a big deal.  Authors would just
     need to use this functionality responsibly.


Received on Sunday, 15 March 2009 17:05:17 UTC