HTML Element Style How to - Style div odd and even


We would like to know how to style div odd and even.


<!--from   w  w  w .  j a  va2s. c o  m-->
<!DOCTYPE html>
<style type='text/css'>
div {
  width: 50px;
  height: 50px;

div:nth-child(odd) {
  background-color: red;

div:nth-child(even) {
  background-color: blue;

The code above is rendered as follows: