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?
> 
> 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 UTC