ul li:first-of-type {background-color: red;}
| 选择符 | 描述 |
|---|---|
| E:first-child | 匹配父元素中的 第一个子元素E |
| E:last-child | 匹配父元素中 最后一个E元素 |
| E:nth-child(n) | 匹配父元素中的 第n个子元素E |
| E:first-of-type | 指定类型E的第一个 |
| E:last-of-type | 指定类型E的最后一个 |
| E:nth-of-type(n) | 指定类型E的第n个 |
- odd:奇数
- even:偶数
- 2n:偶数
- 2n-1:奇数
- 5n:5,10,15…
- n+5:[5, ∞)
- -n+5:[1, 5]
nth-child(n):先选择对应的顺序再选择对应的元素
nth-of-type(n):先将对应元素排序再选择
