css选择器种类,权重,优先级计算,顺序,继承

121 阅读1分钟

选择器种类

基本选择器

通用选择器

*{}

元素(标签)选择器

body{} h1{}

类选择器

.content{}

ID选择器

#content{}

群组选择器

.a,.b,.c{}

关系选择器

后代选择器

.content h1{}

子元素选择器

.content>h1{}

兄弟选择器

.content ~ .title{} [.content后边所有同级的title]
.content + .a {} [兄弟关系]

属性选择器

【type="text"】

结构性伪类选择器

:root
:empty
not()
::before ::after

优先级

id选择器>类选择器>元素选择器 最高的优先级!important

匹配顺序

后来的优先 从右到左

继承

能 font-size font-family color text-indent
否 border
padding margin width height