为什么用户代理样式表是最后一个要应用的样式表? [英] Why is the user agent style sheet the last one style sheet to be applied?

查看:109
本文介绍了为什么用户代理样式表是最后一个要应用的样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过答案,其中谈到了样式表的顺序

I've seen an answer that talked about the order of how the styles sheet is applied in a web page.

我正在研究认证,但遇到了这个问题:

I'm studying for a certification and I faced this question:


问题:

您正在使用HTML5和CSS3创建应用程序。页面的样式
源自五个样式表。样式不是
正确地应用于应用程序中的页面。您需要
确定
浏览器应用样式表的顺序。五个样式表将以什么顺序应用?对于
答案,将样式表类型从样式表类型
的列表移至答案区域,并按照应用
的顺序排列它们。

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

答案:

用户普通样式表
作者普通样式sheet
作者
重要样式表
用户重要样式表
用户代理
样式表

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

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

Why is "user agent style sheets" the last one to be applied? Isn't it the first one because it is the browser default style sheet?

推荐答案

@GoldShip,这不是第一个,因为它是浏览器的默认样式表吗?答案在这里:

@GoldShip, the answer is here:

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

从以上链接引用:


6.4.1级联顺序

6.4.1 Cascading order

查找元素/属性组合,用户代理必须应用以下排序顺序:

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


  1. 查找适用于相关元素和属性的所有声明,目标媒体类型。如果关联的选择器与所讨论的元素匹配,并且目标媒体与所有包含声明的@media规则以及到达样式表的路径上的所有链接上的媒体列表相匹配,则声明适用。

  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.

根据重要性(正常或重要)和来源(作者,用户或用户代理)排序。按升序排列:

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


  1. 用户代理声明

  2. 用户普通声明

  3. 作者正常声明

  4. 作者重要声明

  5. 用户重要声明

  1. user agent declarations
  2. user normal declarations
  3. author normal declarations
  4. author important declarations
  5. user important declarations


  • 通过选择器的特异性对具有相同重要性和起源的规则进行排序:更具体的选择器将覆盖更通用的选择器。伪元素和伪类分别计为普通元素和类。

  • 最后,按指定的顺序排序:如果两个声明具有相同的权重,来源和特异性,则指定后者获胜。导入的样式表中的声明被认为早于样式表本身中的任何声明。


  • 这篇关于为什么用户代理样式表是最后一个要应用的样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆