css - 关于nth-child()的问题
ringa_lee
ringa_lee 2017-04-17 11:45:36
0
2
579

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

ringa_lee
ringa_lee

ringa_lee

reply all(2)
Peter_Zhu
  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)

刘奇

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template