简体   繁体   中英

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.

See http://www.quirksmode.org/css/condcom.html for a more elaborate explanation.

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.

See this picture is from my windows NT (virtual pc) from ie6:

在此输入图像描述

And I changed the user agent in from ie6 in this picture and you can see:

在此输入图像描述

Internet Explorer's own rendering engine / parser looks for these conditionals inside all HTML comments as it builds the DOM from the markup. So they can go anywhere and will be interpreted in the same order they appear.

This is only valid for 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.

It is a IE-specific (and other MS products) functionality only.

Addition: Such clause is used by Outlook also in HTML email messages: <!–[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. The comments are basically skipped by Firefox and all different browsers since they sit inside an HTML comment. But as IE is supposed to read those, it basically does not skip those specific ones.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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