持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第27天,点击查看活动详情
1 :nth-child
-
:nth-child(1)
- 是父元素中的第1个子元素
-
:nth-child(2n)
- n代表任意正整数和0
- 是父元素中的第偶数个子元素(第2 、4、6、8......个)
- 跟:nth-child(even)同义
-
:nth-child(2n + 1)
- n代表任意正整数和0
- 是父元素中的第奇数个子元素(第1、3、5、7......个)
- 跟:nth-child(odd)同义
-
:nth-child(-n + 2)
- 代表前2个子元素
2 :nth-last-child( )
- :nth-last-child(1),代表倒数第一个子元素
- :nth-last-child(-n + 2),代表最后2个子元素
3 :nth-of-type( )、:nth-last-of-type( )
-
:nth-of-type()用法跟:nth-child()类似
- 不同点是:nth-of-type()计数时只计算同种类型的元素
-
:nth-last-of-type()用法跟:nth-of-type()类似
- 不同点是:nth-last-of-type()从最后一个这种类型的子元素开始往前计数
4 否定伪类
-
:not()的格式是:not(x)
- x是一个简单选择器(元素选择器、通用选择器、属性选择器、类选择器、id选择器、伪类)除否定伪类
-
:not(x)表示除x以外的元素
5 其它偶尔会用的
- :root,根元素,就是HTML元素
- :empty代表里面完全空白的元素