Skip to content

How to alternate background colour in html div elements in CSS?

/* 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;
}
See also  How to make a negative number positive in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.