随身笔记
随身笔记

CSS 选择器 选择前几个元素

方法:使用伪类选择器处理

1、选择第n个,n代表数字

:nth-child(n){ }

2、选择列表中的偶数的标签

:nth-child(2n){}

:nth-child(even){ }

3、选择列表中的奇数的标签

:nth-child(2n – 1){ }

:nth-child(odd){ }

4、【负方向范围】选择第1个到第3个

:nth-child(-n + 3){ }

5、【正方向范围】选择从第3个开始的,直到最后

:nth-child(n + 3){ }

6、【限制范围】选择第3个到第6个,取两者的交集

:nth-child(-n+6):nth-child(n+3){ }

7、选择列表中的倒数第n个标签 n为数字

:nth-last-child(n){ }

8、选择第一个 ( first-child表示选择列表中的第一个标签 )

:first-child{ }

9、选择最后一个 ( last-child表示选择列表中的最后一个标签 )

:last-child{ }

 

https://www.cnblogs.com/zigood/p/15660249.html

随身笔记

CSS 选择器 选择前几个元素
方法:使用伪类选择器处理 1、选择第n个,n代表数字 :nth-child(n){ } 2、选择列表中的偶数的标签 :nth-child(2n){} :nth-child(even){ } 3、选择列表中的奇数的标签 …
扫描二维码继续阅读
2023-04-13