Reputation: 29
I'm trying to make pair or unpair divs from a container to have a different background. For example the first one has a red background, the second blue, the third red the fourth blue and so...
This is my code:
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
div { width:50px; height:50px; background:red; }
I really don't know how to achieve this. I don't know if I need only css or jquery too.
Thank you.
Upvotes: 0
Views: 277
Reputation: 1397
use pseudo selector nth-child of CSS property . By using this u can select odd even node
div:nth-child(odd) { background-color: #FF0000; }
div:nth-child(even) { background-color: #0000FF; }
Upvotes: 0