Divs with alternating colors [duplicate]

2

I have an ajax that shows the results to me in a JSON, I need the colors of <div> to alternate: in the first gray color, the second white, the third gray, the fourth white, and so on. How do I do that? I can put class 1 in the even div and class 2 in the odd div, I just need to know how to do it.

Follow my example code in html:

<div class="historico_registroA">
    <span class="historico_registro_data">12/10/2016 às 11:00</span>
</div>
<div class="historico_registroB">
    <span class="historico_registro_data">22/11/2016 às 15:30</span>
</div>
<div class="historico_registroA">
    <span class="historico_registro_data">07/12/2016 às 18:00</span>
</div>
<div class="historico_registroB">
    <span class="historico_registro_data">09/12/2016 às 15:00</span>
</div>
    
asked by anonymous 02.12.2016 / 17:10

1 answer

5

In css think it would be easier, you're trying to make the famous zebra list right? (correct me if I'm wrong).

suaClasse:nth-child(even) { background: #CCC; }
suaClasse:nth-child(odd) { background: #FFF; }
    
02.12.2016 / 17:23