问题
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:
- User Agent
- User Normal
- Author Normal
- Author Important
- User Important
As defined in the specification
回答2:
CSS declarations are applied in this order (from lowest to highest priority):
- user agent declarations (the default styles your browser applies to elements)
- user normal declarations (a user's own stylesheet if they're using one)
- author normal declarations (this is your normal stylesheet)
- author important declarations (anything your mark important)
- 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):
- Browser declarations
- User normal declarations
- Author normal declarations
- Author important declarations
- 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