| 选择器 | 含义
| 示例
|
E:root
| 匹配文档的根元素,对于HTML文档,就是HTML元素
| p:nth-child(3) { color:#f00; }
p:nth-child(odd) { color:#f00; }
p:nth-child(even) { color:#f00; }
p:nth-child(3n+0) { color:#f00; }
p:nth-child(3n) { color:#f00; }
tr:nth-child(2n+11) { background:#ff0; }
tr:nth-last-child(2) { background:#ff0; }
p:last-child { background:#ff0; }
p:only-child { background:#ff0; }
p:empty { background:#ff0; }
|
E:nth-child(n)
| 匹配其父元素的第n个子元素,第一个编号为1
|
E:nth-last-child(n)
| 匹配其父元素的倒数第n个子元素,第一个编号为1
|
E:nth-of-type(n)
| 与:nth-child()作用类似,但是仅匹配使用同种标签的元素
|
E:nth-last-of-type(n)
| 与:nth-last-child() 作用类似,但是仅匹配使用同种标签的元素
|
E:last-child
| 匹配父元素的最后一个子元素,等同于:nth-last-child(1)
|
E:first-of-type
| 匹配父元素下使用同种标签的第一个子元素,等同于:nth-of-type(1)
|
E:last-of-type
| 匹配父元素下使用同种标签的最后一个子元素,等同于:nth-last-of-type(1)
|
E:only-child
| 匹配父元素下仅有的一个子元素,等同于:first-child:last-child或 :nth-child(1):nth-last-child(1)
|
E:only-of-type
| 匹配父元素下使用同种标签的唯一一个子元素,等同于:first-of-type:last-of-type或 :nth-of-type(1):nth-last-of-type(1)
|
E:empty
| 匹配一个不包含任何子元素的元素,注意,文本节点也被看作子元素
|