Languages
[Edit]
EN

CSS - style last element only

0 points
Created by:
Laylah-Walsh
294

In this article, we would like to show you how to style the last element only using CSS.

Quick solution:

element:last-child {
  /* style properties here */
}

 

Practical example

In this example, we create a style for the last div element only using :last-child.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    div:last-child {
      background: yellow;
    }

  </style>
</head>
<body>
    <div>div 1</div>
    <div>div 2</div>
    <div>div 3</div>
</body>
</html>
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