搜尋

首頁  >  問答  >  主體

css - 关于nth-child()的问题

span:nth-child(-n+3)
匹配前三个子元素中的span元素
为什么是匹配前3个元素??如果n是0开始的话,不应该是n+3吗?

ringa_leeringa_lee2863 天前620

全部回覆(2)我來回復

  • 天蓬老师

    天蓬老师2017-04-17 11:47:36

    1. span:nth-child(n+3) 感覺是匹配的從第三個往後的所有 span 元素

    2. n 應該是從 0,1,2,… 加上負號才能保證 nth-chlid(裡面的數字小於等於三)

    回覆
    0
  • 怪我咯

    怪我咯2017-04-17 11:47:36

    Example:

    -n+6 / represents the first 6 elements of the list /

    The values of A and B can be negative, but only the positive results of An+B, >for n ≥ 0, are used.

    你可以這樣理解,n是從0開始計數(0,1,2...)
    所以(-n+6) => (6,5,4,3,2,1)所以是前六個
    上面的引文已經說了,只有正數會被使用。

    回覆
    0
  • 取消回覆