We would like to know how to style div odd and even.
<!--from w w w . j a va2s. c o m-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {
width: 50px;
height: 50px;
}
div:nth-child(odd) {
background-color: red;
}
div:nth-child(even) {
background-color: blue;
}
</style>
</head>
<body>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</body>
</html>
The code above is rendered as follows: