even child and odd child selector

 Index.html file:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<ul>
<li> list item 1</li>
<li> list item 2</li>
<li> list item 3</li>
<li> list item 4</li>
</ul>

<Ol>
<li> ol 1</li>
<li> ol 2</li>
<li> ol 3</li>
<li> ol 4</li>
</Ol>


</body>

</html>

style.css file:

ul>li:nth-child(2n) {

color: blueviolet;
}

ol>li:nth-child(2n+1) {

color: brown;
}

Output:

  • list item 1
  • list item 2
  • list item 3
  • list item 4
  1. ol 1
  2. ol 2
  3. ol 3
  4. ol 4

Comments