search

Home  >  Q&A  >  body text

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

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

ringa_leeringa_lee2779 days ago576

reply all(2)I'll reply

  • 天蓬老师

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

    1. span:nth-child(n+3) It seems to match all span elements from the third one onwards

    2. n should start from 0, 1, 2,... and add a negative sign to ensure nth-chlid (the number inside is less than or equal to three)

    reply
    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.

    You can understand it this way, n starts counting from 0 (0,1,2...)
    So (-n+6) => (6,5,4,3,2,1) So the first six
    As the quote above already said, only positive numbers will be used.

    reply
    0
  • Cancelreply