Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Created December 17, 2020 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanaf1979/adcdfd1991818f3e09b49bb641e0f192 to your computer and use it in GitHub Desktop.
Save vanaf1979/adcdfd1991818f3e09b49bb641e0f192 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>nth-of-type even and odd selectors</title>
</head>
<body>
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ul>
<style>
body {
padding: 0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
ul {
width: 200px;
list-style: none;
padding: 0;
}
li {
padding: 0.5rem 1rem;
}
ul li:nth-of-type(odd) {
background: green; /* This will select all odd children */
}
ul li:nth-of-type(even) {
background: orange; /* This will select all even children */
}
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment