css选择符:
- 通配:(*) 0
- id选择器:(#) 100
- 类选择器:(.) 10
- 标签选择器:(tag) 1
- (相邻)父子选择器:( ),(>) 10
- (相邻)兄弟选择器:(~),(+) 10
- 属性选择器:(a[href]) 10
- 伪类选择器:(a:hover, a:focus, a:active ) 10
- ( li:nth-child, first:nth-child,, last:nth-child)
- 伪元素选择器:(::before)(::after)(::selection) 1
伪类选择器和伪元素选择器的区别
伪类:依附于已经存在的元素,使用冒号作为表示,可以链式
伪元素:使用双冒号为表示,一般用于创建虚拟元素定义其样式,不可以链式
优先级
!important > 内联 >id > class > tag > 通配符
权重计算
- 内联样式: 1000
- id选择器: 100
- 类选择器: 10
- 标签&伪元素选择器: 1
- 通配符,+,>: 0
css3新增的选择器
:enabled,:disabled:控制表单控件的禁用状态
:checked:单选框或复选框被选中
:has:
:not:匹配不符合选择器的元素
css属性那些可以继承:
文字系列:font-size,color,line-height,text-align...
不可继承属性:
border,padding,margin