How to select only first three elements using CSS

前端 未结 1 906
萌比男神i
萌比男神i 2021-01-15 18:46

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

相关标签:
1条回答
  • 2021-01-15 19:34

    You can do it like this:

    section > figure:nth-child(-n+3) {
      border: 1px solid;
    }
    <section>
      <figure>1</figure>
      <figure>2</figure>
      <figure>3</figure>
      <figure>4</figure>
      <figure>5</figure>
      <figure>6</figure>
    </section>

    0 讨论(0)
提交回复
热议问题