W3C home > Mailing lists > Public > www-style@w3.org > March 2009

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

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Sat, 14 Mar 2009 10:16:09 -0700
Message-ID: <49BBE659.5030105@terrainformatica.com>
To: Mike Wilson <mikewse@hotmail.com>
CC: 'www-style' <www-style@w3.org>
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?
> 
> Example targeting all <li>s:
>   li.item:nth-child(odd) {background-color:grey;}
>   <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
> 
> Example targeting subset of <li>s:
>   li.item:nth-child(odd) {background-color:grey;}
>   <li>...</li>             --> index 1 (not selected)
>   <li class="item">a</li>  --> index 2 = even
>   <li class="item">b</li>  --> index 3 = odd = grey
>   <li class="item">c</li>  --> index 4 = even
> 
> In the second example we see that the first <li> "consumes"
> the first odd entry from the formating rule, although it is
> not selected by this rule. This makes the whole striped
> formating visually shift one step forward as a side effect of
> introducing an element not covered by the rule.
> 
> 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
> ?
> 

That will not work, sorry. Selector

   li.item:nth-child(odd)

would require scanning of the whole DOM tree
in order to resolve the style.

Think about multiple lists in your document.
To be able to find style for particular LI you
would need to scan all lists.

And if you will say dynamically add the item in one of them
all other li.item in the DOM need to be recalculated.

-- 
Andrew Fedoniouk.

http://terrainformatica.com
Received on Saturday, 14 March 2009 19:20:01 GMT

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