Basic example

by Dominik Wilk

HTML

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child -->

<div>
  <p class="test">This text is selected!</p>
  <p>This text isn't selected.</p>
</div>

<div>
  <h2>This text isn't selected: it's not a `p`.</h2>
  <p class="test">This text isn't selected.</p>
</div>

CSS

div .test:first-child {
  color: lime;
  background-color: black;
  padding: 5px;
}