We can easily change the background color of div’s even and odd index using the:nth-child pseudo-class with the even and odd keywords, respectively. Odd and even are keywords that can be used to match child elements whose index is odd or even (the index of the first child is 1). Here, we specify two different background colors for odd and even p elements.


<!DOCTYPE html>
<title>Even Odd Example</title>
<style type=”text/css”>
div :nth-child(even){
background-color: yellow;
div :nth-child(odd){
background-color: blue;
<div id=”main”>




The post How to Style Even and Odd Div. appeared first on PHPFOREVER.


Leave a Reply