[css] Please describe the css weight calculation rules

[css] Please describe the css weight calculation rules

Weight value calculation
Selector case weight value
!important !important Infinity
inline style style="…" 1000
ID #id 100
class .class 10
attribute [type='text'] 10
pseudo-class: hover 10
tag p 1
pseudo-element: :first-line 1
adjacent selector, child selector, wildcard *> + 0
comparison rules

1000>100。也就是说从左往右逐个等级比较,前一等级相等才往后比。
在权重相同的情况下,后面的样式会覆盖掉前面的样式。
继承属性没有权重值
通配符、子选择器、相邻选择器等的。虽然权值为0,但是也比继承的样式优先。
ie6以上才支持important,并且尽量少用它。

Personal profile

I am a song, welcome to share front-end and back-end knowledge with you. It is easy to give up,
but it must be cool to persist. Welcome everyone to discuss

Main directory

Clear the front-end interview questions with song

Guess you like

Origin blog.csdn.net/weixin_43392489/article/details/113810767