【问题标题】:How to select only first three elements with CSS如何使用 CSS 只选择前三个元素
【发布时间】:2018-10-28 15:04:22
【问题描述】:

如何使用:nth-child()选择器只选择前三个元素

section > figure:nth-child( ? ) {
  /* ... */
}
<section>
  <figure>1</figure> <!-- select this -->
  <figure>2</figure> <!-- and this -->
  <figure>3</figure> <!-- and this -->
  <figure>4</figure>
  <figure>5</figure>
  <figure>6</figure>
</section>

【问题讨论】:

标签: html css css-selectors


【解决方案1】:

你可以这样做:

section &gt; 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>

【讨论】:

    猜你喜欢
    • 2016-05-09
    • 2016-12-01
    • 2014-09-14
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    相关资源
    最近更新 更多