Style sheets priority order

我的梦境 提交于 2019-12-28 14:01:14

问题


If I have the following style sheets:

user important declarations
user normal declarations
author normal declarations
user agent declarations
author important declarations

and need to apply them from highest priority to lowest priority, in which order should I use them?


回答1:


The correct order of precedence is, from least important to most important:

  1. User Agent
  2. User Normal
  3. Author Normal
  4. Author Important
  5. User Important

As defined in the specification




回答2:


CSS declarations are applied in this order (from lowest to highest priority):

  1. user agent declarations (the default styles your browser applies to elements)
  2. user normal declarations (a user's own stylesheet if they're using one)
  3. author normal declarations (this is your normal stylesheet)
  4. author important declarations (anything your mark important)
  5. user important declarations (any important styles from the user's stylesheet)



回答3:


Below content is taken from here.

Style property can appear in any number of style sheets, and several times inside a single style sheet. Therefore, order of applying the rules is very important. This is called the "cascade" order. According to CSS2 spec, the cascade order is (from low to high):

  1. Browser declarations
  2. User normal declarations
  3. Author normal declarations
  4. Author important declarations
  5. User important declarations

a) The browser declarations are least important;
b) User overrides the author only if the declaration was marked as important.
c) Declarations with the same order will be sorted by specificity and then the order they are specified.
d) The HTML visual attributes are translated to matching CSS declarations.
e) They are treated as author rules with low priority.



来源:https://stackoverflow.com/questions/13638038/style-sheets-priority-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!