css nth-of-type nth-of-child(公式)

知识点:

1.nth-of-type公式里的n是从0开始计算

2.nth-of-type获取到的元素,是从1开始计算

3.如果需要获取或排除前面的元素,用nth-of-type

   如果需要获取或排除前面的元素,用nth-last-of-type

例子:

1.获取前三个:nth-of-type(-n+3),从n=0开始计算,分别得到第3,第2,第1个元素

2.获取前三个除外的:nth-of-type(n+4),从n=0开始计算,分别得到第4,第5,第5+个元素

3.获取后三个:nth-last-of-type(-n+3),从n=0开始计算,分别得到从后面数起的第3,第2,第1个元素

4.获取前三个除外的:nth-last-of-type(n+4),从n=0开始计算,分别得到从后面数起的第4,第5,第5+个元素

如:triangle:nth-child(3n-1)/如:triangle:nth-child(3n+1)

 

posted @ 2021-01-26 12:01  文采呱呱  阅读(375)  评论(0编辑  收藏  举报