Published
- 1 min read
how to alternate background colour in html div elements in css
The solution for this is noted below
how to alternate background colour in html div elements in css
Solution
/* to color odd children in parent-container with children of type div */
#parent-container > div:nth-child(odd) {
background-color:red;
}
/* to color even children in parent-container with children of type div */
#parent-container > div:nth-child(even) {
background-color:red;
}
Try other methods by searching on the site. That is if this doesn’t work