CSS3学习笔记
1. 伪类选择器
CSS3之前的伪类共有:::first-line,::first-letter, :after, :before, :hover, :active, :visited, :focus, :link,:first-child, :lang这11种。
CSS3新增了许多选择器,下面列出常见的几种。
1. :nth-child(n) 某个父元素的第n个子元素。(CSS3)
2. :nth-child(2n) 选择偶数项。(CSS3)
3. :nth-child(n+5) 从第五个元素开始全选。(CSS3)
4. :nth-last-child(n) 获取倒数第n个元素。(CSS3)
5. li:nth-of-type(n) 获取第n个li元素。
6. li:nth-last-of-type(n) 获取倒数第n个li元素
7. :last-child 最后一个子元素。(CSS3)
8. :first-of-type: 相当于:nth-of-type(1)。
9. :last-of-type: 相当于:nth-last-of-type(1)。
10. only-child: 获取只有一个子元素的子元素。
11. only-of-type: 类似于only-child,区别于不指定type时,会选择body。
12. :root 选择文档的根元素。(CSS3)
13. :empty 选择没有任何内容的元素。(CSS3)
14. :target选择当前被选中的锚点元素。(CSS3)