伪类伪元素
伪类选择器
可以理解为描述元素的某种状态
常用伪类
a标签的4种伪类(要按顺序书写:link、visited、hover、active)
- :link:元素链接点击前的样式
- :visited;元素链接点击后的样式
- :hover:鼠标覆盖在元素上
- :active:鼠标在元素上并按下左键
其他伪类
- :focus:获取焦点的样式
- :first-child:第一个子级
- :first-of-type:特定的第一个子级
- :last-child:最后一个子级
- :last-of-type:特定的最后一个子级
- :nth-child(n):第n个子元素
- :nth-of-type(n):推荐/指定类型的第n个子元素
- :nth-last-child(n):倒数第n个子元素
- :nth-last-of-type(n):指定类型的倒数第n个子级
伪元素选择器
可以理解为某个元素的子元素,但不存在于html
选择器
- ::after:元素后的内容
- ::before:元素前的内容
- ::first-line:文本的第一行样式
- :;first-letter:文本的首字母,只用于块元素
- ::placeholder:只用于表单的提示文本