Style sheets priority order

前端 未结 3 933
南旧
南旧 2020-12-10 00:57

If I have the following style sheets:

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


        
相关标签:
3条回答
  • 2020-12-10 01:16

    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)
    0 讨论(0)
  • 2020-12-10 01:22

    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.

    0 讨论(0)
  • 2020-12-10 01:32

    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

    0 讨论(0)
提交回复
热议问题