css 选择第某个元素到第某个元素

109 阅读1分钟

css 选择第某个元素到第某个元素

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

:nth-child(n){ }

2、偶数标签

:nth-child(2n){}

:nth-child(even){ }

3、奇数标签

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

:nth-child(odd){ }

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

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

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

:nth-child(n + 5){ }

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

:nth-child(-n+8):nth-child(n+2){ }

7、倒数第n个标签 (n为数字)

:nth-last-child(n){ }

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

:first-child{ }

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

:last-child{ }

注:blog.csdn.net/Menqq/artic…