CSS 的后代伪类选择器共五对,两种类型(我命名为:child 型与 type 型),分别是:
child 型 | type 型 |
---|---|
:first-child |
:first-of-type |
:last-child |
:last-of-type |
:only-child |
:only-of-type |
:nth-child(n) |
:nth-of-type(n) |
:nth-last-child(n) |
:nth-last-of-type(n) |
两种类型的主要区别在于查找元素的顺序,child 型先查找元素位置,再查找元素类型;而 type 型则刚好相反,先找类型,后找位置。