CSS伪类选择器 -- nth-child(an+b):

CSS伪类选择器 - nth-child(an+b):
1、nth-child(an):倍数写法,匹配倍数为a的所有元素
2、:nth-child(an+b) 与 :nth-child(an-b),倍数偏移写法
n从0开始计数,b是偏移量

tr:nth-child(3n+1){background:orange;}/*n=(0,1,2....),匹配第1、第4、第7、…*/
tr:nth-child(3n+5){background:orange;}/*n=(0,1,2....),匹配第5、第8、第11、…*/
tr:nth-child(3n-5){background:orange;}/*n=(0,1,2....),匹配第1、…*/

3、nth-child(-an+b),另类倍数匹配,它是倒着算的,先匹配第b个,所以匹配数不会超过b个

tr:nth-child(-n+3){background: gray;}/*n=(0,1,2...),匹配第3个、第2个、第1个,也就是匹配前8个*/

你可能感兴趣的:(CSS伪类选择器 -- nth-child(an+b):)