gpt4 book ai didi

css - 为什么用户代理样式表是最后一个要应用的样式表?

转载 作者:行者123 更新时间:2023-12-02 10:33:17 26 4
gpt4 key购买 nike

我看到了answer 讨论了样式表在网页中的应用顺序。

我正在学习认证,我遇到了这个问题:

Question:
You are creating an application by using HTML5 and CSS3. The styles for the pages are derived from five style sheets. The styles are not being applied correctly to the pages in the application. You need to determine the order in which the style sheets will be applied by the browser. In which order will the five style sheets be applied? To answer, move the style sheet types from the list of style sheet types to the answer area and arrange them in the order that they will be applied.

user agent style sheets
user normal style sheets
author normal style sheets
author important style sheets
user important style sheets

Answer:

user normal style sheets
author normal style sheets
author important style sheets
user important style sheets
user agent style sheets

为什么“用户代理样式表”是最后一个应用的?第一个不是因为它是浏览器默认样式表吗?

最佳答案

@GoldShip,答案在这里:

http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascade

引用上述链接:

6.4.1 Cascading order

To find the value for an element/property combination, user agents must apply the following sorting order:

  1. Find all declarations that apply to the element and property in question, for the target media type. Declarations apply if the associated selector matches the element in question and the target medium matches the media list on all @media rules containing the declaration and on all links on the path through which the style sheet was reached.

  2. Sort according to importance (normal or important) and origin (author, user, or user agent). In ascending order of precedence:

    1. user agent declarations
    2. user normal declarations
    3. author normal declarations
    4. author important declarations
    5. user important declarations
  3. Sort rules with the same importance and origin by specificity of selector: more specific selectors will override more general ones. Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively.
  4. Finally, sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins. Declarations in imported style sheets are considered to be before any declarations in the style sheet itself.

关于css - 为什么用户代理样式表是最后一个要应用的样式表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com