Skip to content Skip to sidebar Skip to footer

How To Select Only First Three Elements With CSS

How can I select only first three elements with the :nth-child() selector?

Solution 1:

You can do it like this:

section > figure:nth-child(-n+3) {background: Aqua}
<section>
  <figure>1</figure>
  <figure>2</figure>
  <figure>3</figure>
  <figure>4</figure>
  <figure>5</figure>
  <figure>6</figure>
</section>

Post a Comment for "How To Select Only First Three Elements With CSS"