how to alternate background colour in html div elements in css

Solutions on MaxInterview for how to alternate background colour in html div elements in css by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to alternate background colour in html div elements in css"
Lois
27 Apr 2018
1/* to color odd children in parent-container with children of type div */
2#parent-container > div:nth-child(odd) {
3 background-color:red;
4}
5
6/* to color even children in parent-container with children of type div */
7#parent-container > div:nth-child(even) {
8 background-color:red;
9}