Languages
[Edit]
EN

CSS - style first element only

0 points
Created by:
Inayah-Alexander
437

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

Quick solution:

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

 

Practical example

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

// ONLINE-RUNNER:browser;

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

    div:first-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