HTML to determine IE version

Source: Internet
Author: User
Tags html comment

1 <!--[if! ie]><! -can be recognized except IE<!--<! [EndIf] -2 <!--[If ie]> all IE recognizable <! [EndIf] -3 <!--[If IE 5.0]> only IE5.0 can be identified <! [EndIf] -4 <!--[If IE 5]> only IE5.0 and IE5.5 can be identified <! [EndIf] -5 <!--[If GT IE 5.0]> IE5.0 and IE5.0 above can be identified <! [EndIf] -6 <!--[If IE 6]> only IE6 recognizable <! [EndIf] -7 <!--[If Lt IE 6]> IE6 and IE6 The following versions are recognized <! [EndIf] -8 <!--[If GTE IE 6]> IE6 and IE6 above are recognized <! [EndIf] -9 <!--[If IE 7]> only IE7 recognizable <! [EndIf] -Ten <!--[If Lt IE 7]> IE7 and IE7 The following versions are recognized <! [EndIf] - One <!--[If GTE IE 7]> IE7 and IE7 above are recognized <! [EndIf] -

<!--[If LTE IE 6]>......<! [endif]-->

Ite:less than or equal to meaning is less than or equal to IE6 browser, for the conditions of IE browser comments, commonly used in csshack, for IE, JS and so on.

In the process of learning and applying Web standard Web pages, the compatibility of Web pages with browsers is an issue that is frequently contacted. Because Microsoft's Internet Explorer (IE) occupies more than half of the browser market, in addition to Firefox, opera and so on. These browsers need to be compatible.

At the same time, in the case of IE, because of the upgrade of the version of IE, the current visitors to use the main stay in IE5 (IE5.5), IE6 and IE7 three of the version. These 3 versions are not displayed in the same way as we do for the Web Standard Web page (XHTML+CSS) interpretations we make. Also, other non-ie browsers and IE do not have the same explanation for some CSS. Therefore, it is possible to define the relevant attribute by using the proprietary condition annotation in IE browser.

Conditional annotations can only be used with Explorer 5+ Windows (IE) (conditional comments are supported from IE5). If you have more than one IE installed, the conditional comment (Conditional comments) will be the highest version of IE (currently IE 7).

Conditional annotations are only available under Windows Internet Explorer (IE), so we can use conditional annotations to add special instructions to IE.

Popular point, conditional annotations are some if judgments, but these judgments are not executed in the script, but are executed directly in the HTML code, such as:

<!-- [If ie]> here is the normal HTML code <! [EndIf]  -
    1. The basic structure of the conditional comment is the same as the HTML comment (<!---->). Browsers outside of IE will therefore treat them as plain annotations and ignore them entirely.
    2. IE will determine whether the content in the conditional comment is parsed as if the normal page content is parsed, based on the IF condition.
    3. Conditional annotations Use HTML annotation structures, so they can only be used in HTML files and not in CSS files. You can use the following code to detect the current version of IE browser (note: In non-IE browser is not see the effect)
1 <!--[If Ie]>2 3 <!--[if IE 5]>4 5 <! [EndIf] -6 7       <!--[If IE 5.0]>8 9 <! [EndIf] -Ten  One       <!--[If IE 5.5]> A  - <! [EndIf] - -  the       <!--[If IE 6]> -  - <! [EndIf] - -  +       <!--[If IE 7]> -  + <! [EndIf] - A <![endif]-->

If the current browser is IE, but the version is lower than IE5, how to do it, you can use <!--[if LS ie 5]>, of course, according to the conditional annotation can only be in ie5+ environment, so <!--[if LS ie 5]> will not be executed at all.

    • LTE: is less than or equal to the shorthand, that is, smaller than or equal to the meaning.
    • LT: is less than shorthand, that is, smaller than the meaning.
    • GTE: is greater than or equal to the shorthand, that is, greater than or equal to the meaning.
    • GT: is greater than shorthand, that is, the meaning of greater than.
    • ! : Is not equal to the meaning of the JavaScript is not equal to the same judge

Conditional comments belong to CSS hack? Does the conditional judgment belong to CSS hack?

Strictly speaking, it belongs to CSS hack. Because it's like any other real CSS hack, it allows us to give special styles to some browsers, and it doesn't depend on a browser bug to control the other browser (style). In addition, conditional judgment can be used to do things beyond the bounds of the CSS hack (although this rarely happens).

Because the conditional judgment does not depend on the hack of a particular browser, it is a thoughtful feature, so I believe it can be used with confidence. Of course, other browsers may also support conditional judgments (not so far), but it seems that they should not use syntax such as <!--[if ie]>.

How conditional annotations should be applied

This article at the beginning of the explanation, because the browser version of the Internet Explorer for our production of the Web Standard page interpretation is not the same, in particular, the interpretation of the CSS is different, we are compatible with these, we can use conditional comments to define, and finally achieve the purpose of compatibility. Like what:

1 <!--by default, the CSS.CSS style sheet is called first -2 <Linkrel= "stylesheet"type= "Text/css"href= "Css.css" />3 4 <!--[If IE 7]>5 <!--if IE version is 7, call IE7.CSS style sheet -6 <Linkrel= "stylesheet"type= "Text/css"href= "Ie7.css" />7 <![endif]-->8 9 <!--[If LTE IE 6]>Ten <!--if IE browser version is less than or equal to 6, call IE.CSS style sheet - One <Linkrel= "stylesheet"type= "Text/css"href= "Ie.css" /> A <![endif]-->

This distinguishes between IE7 and IE6 down the browser to the implementation of CSS, to achieve compatibility. At the same time, the first line of the default css.css can also be compatible with other non-IE browser implementations.

Note: The default CSS style should be in the first line of the HTML document, and all content judged by the conditional comment must be behind the default style.

For example, the following code, in IE, the execution of the display as red, and in non-IE browser display as black. If the conditional annotation is judged on the first line, it cannot be implemented. This example can explain the compatibility problem between IE and non-IE browser.

1 <styletype= "Text/css">2 Body{3 Background-color:#000;4 }5 </style>6 7 <!--[If Ie]>8 <style type= "Text/css" >9 body{Ten background-color: #F00; One } A </style> - <! [EndIf] -

At the same time, someone will try to use <!--[if! Ie]> to define the condition under the non-IE browser, but note: The conditional comment can only be executed under IE browser, this code does not execute the definition under this condition under non-ie browsing, but ignores it as a comment. Normal is the default style, for IE browser needs special processing, only to make conditional comments.

In the HTML file, but not in the CSS file.

HTML to determine IE version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.