简体   繁体   English

条件评论从哪里获取信息?

[英]Where do conditional comments get their info from?

Example: 例:

<!--[if IE 6]>You suck!<![endif]-->

Does it get its information from the user-agent? 它是否从用户代理获取其信息?

These are called conditional comments , and are only supported by IE, so in short, they're a feature of IE. 这些被称为conditional comments ,并且仅由IE支持,因此简而言之,它们是IE的一个特征。

See http://www.quirksmode.org/css/condcom.html for a more elaborate explanation. 有关更详细的说明,请参阅http://www.quirksmode.org/css/condcom.html

To answer your question yes it takes information from the user agent but I will just work in IE and it won't work when you change the user agent in chrome or ff. 要回答你的问题是,它需要来自用户代理的信息,但我将只在IE中工作,当你用chrome或ff更改用户代理时,它将无法工作。

See this picture is from my windows NT (virtual pc) from ie6: 从ie6看到这张图片来自我的Windows NT(虚拟PC):

在此输入图像描述

And I changed the user agent in from ie6 in this picture and you can see: 我在这张图片中从ie6更改了用户代理,你可以看到:

在此输入图像描述

Internet Explorer's own rendering engine / parser looks for these conditionals inside all HTML comments as it builds the DOM from the markup. Internet Explorer自己的渲染引擎/解析器在所有HTML注释中查找这些条件,因为它从标记构建DOM。 So they can go anywhere and will be interpreted in the same order they appear. 所以他们可以去任何地方,并按照他们出现的顺序进行解释。

This is only valid for Internet Explorer . 这仅适用于Internet Explorer This will not be read from any other browser and will be taken as comment (that's why it is looking exactly as comment after all). 这将不会从任何其他浏览器中读取,并将被视为评论 (这就是为什么它看起来完全像评论)。 It is not CSS but HTML comment, where IE knowns if the version match to do what is inside - to load css or something else. 它不是CSS而是HTML注释,其中IE知道版本是否匹配以执行内部操作 - 加载css或其他内容。

It is a IE-specific (and other MS products) functionality only. 它仅是IE特定(和其他MS产品)功能。

Addition: Such clause is used by Outlook also in HTML email messages: <!–[if gte vml 1]> 添加:Outlook也在HTML电子邮件中使用此类子句: <!–[if gte vml 1]>

According to MSDN, IE conditional comments are using Version Vectors that grab the version of IE and Windows Version that the browser is running on. 根据MSDN,IE条件注释使用版本向量来获取运行浏览器的IE和Windows版本。 The comments are basically skipped by Firefox and all different browsers since they sit inside an HTML comment. Firefox和所有不同的浏览器基本上都会跳过这些注释,因为它们位于HTML注释中。 But as IE is supposed to read those, it basically does not skip those specific ones. 但是,由于IE应该读取它们,它基本上不会跳过那些特定的。

我认为你反过来了: 浏览器本身渲染CSS当且仅当浏览器可以解析指令时(在这种情况下, [if IE]指令)它不是服务器提供动态CSS取决于用户代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM