EN
CSS - style odd elements only
0
points
In this article, we would like to show you how to style odd elements only using CSS.
Quick solution:
li:nth-child(odd) {
/* style properties here */
}
Practical example
In this example, we create an unordered list and style its odd elements using :nth-child(odd); pseudo class.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<style>
li:nth-child(odd) {
background: yellow;
}
</style>
</head>
<body>
<ul>
<li>element 1</li>
<li>element 2</li>
<li>element 3</li>
<li>element 4</li>
</ul>
</body>
</html>