7
I have the following scenario:
HTML:
<div class='linha visivel'>Visivel</div>
<div class='linha visivel'>Visivel</div>
<div class='linha oculto' style='display:none'>Invisivel</div>
<div class='linha visivel'>Visivel</div>
CSS:
.visivel:nth-child(odd) { background: yellow }
.visivel:nth-child(even) { background: green }
Result found:
- 1st line with visible class YELLOW
- 2nd line with visible class GREEN
- 3rd line with visible class GREEN
Expected result:
- 1st line with visible class YELLOW
- 2nd line with visible class GREEN
- 3rd line with visible class YELLOW
From what I understand, Nth-Child should paint alternately the Divs with the visible class. But as there is a div hidden in the middle he ends up not doing it properly.
Am I wrong about the behavior? How to correct?
The same question you have: http://stackoverflow.com/questions/26057925/select-odd-even-child-excluding-the-hidden-child (Marked solution)
– Rafael Withoeft
The behavior is the same, because the selector works based on DOM nodes and does not apply only to what is selected by CSS. What you could do in this case is paint the lines using Javascript, for example.
– utluiz
I could do with jQuery, but I was just trying to avoid.
– Joao Paulo