Languages
[Edit]
EN

CSS - style odd elements only

0 points
Created by:
Evania
314

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>

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join