Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS优先级 #4

Open
ustccjw opened this issue Oct 18, 2014 · 0 comments
Open

CSS优先级 #4

ustccjw opened this issue Oct 18, 2014 · 0 comments
Labels

Comments

@ustccjw
Copy link
Owner

ustccjw commented Oct 18, 2014

CSS优先级

理清CSS的优先级还是很有必要的

总的原则

  1. 内部样式表 > 外部样式表 > 外部样式表引用的样式表(import) > 继承样式 > 浏览器自带样式
  2. !important样式的优先级最高
  3. 同等优先级看出现的顺序,出现在后面的样式优先级高

CSS特异性

选择器的特异性由 CSS2 规范定义如下:

  1. 如果声明来自于“style”属性,而不是带有选择器的规则,则记为 1,否则记为 0 (= a)
  2. 记选择器中 ID 属性的个数 (= b)
  3. 记选择器中其他属性和伪类的个数 (= c)
  4. 记选择器中元素名称和伪元素的个数 (= d)
  5. 将四个数字按 a-b-c-d 这样连接起来(位于大数进制的数字系统中),构成特异性。

特异性高的样式优先级高

@ustccjw ustccjw added the blog label Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant