If lte IE if gte IE

Source: Internet
Author: User
The code is as follows: Copy code

<! -- [If lte IE 6]>
<! [Endif] -->
IE6 and earlier versions are visible


<! -- [If lte IE 7]>
<! [Endif] -->
IE7 and earlier versions are visible


<! -- [If IE 6]>
<! [Endif] -->
Only the IE6 version is visible.


<! [If! IE]>
<! [Endif]>
Versions other than IE


<! -- [If lt IE 8]>
<! [Endif] -->
IE8 and earlier versions are visible

 


<! -- [If gte IE 7]>
<! [Endif] -->
IE7 and earlier versions are visible


Usage:
(1)
You can use the following code to check the current version of IE (note: it is ineffective in non-IE browsers)

The code is as follows: Copy code
<! -- [If IE]>
<H1> you are using IE <! -- [If IE 5]>
<H2> version 5 <! [Endif] -->
<! -- [If IE 5.0]>
<H2> Version 5.0 <! [Endif] -->
<! -- [If IE 5.5]>
<H2> version 5.5 <! [Endif] -->
<! -- [If IE 6]>
<H2> version 6 <! [Endif] -->
<! -- [If IE 7]>
<H2> Version 7 <! [Endif] -->
<! [Endif] -->


If the current browser is IE but the version is lower than IE5, what should I do? You can use it <! -[If ls IE 5]>, of course, the condition annotation can only be in the IE5 + environment, so <! -[If ls IE 5]> It is not executed at all.
Lte: short for Less than or equal to, that is, Less than or equal.
Lt: short for Less than, that is, Less.
Gte: short for Greater than or equal to, that is, Greater than or equal.
Gt: short for Greater than, that is, Greater.
! : It means not equal to, which is the same as the non-equal identifier in javascript.

 


(2)
How to apply conditional comments
This article explains at the beginning, because browsers of different IE versions have different interpretations of the WEB standard pages we have created. Specifically, they have different interpretations of CSS. To be compatible with these, you can use condition annotations to define them separately to achieve compatibility. For example:
<! -- First use the css.css style sheet -->

The code is as follows: Copy code

<Link rel = "stylesheet" type = "text/css" href = "css.css"/>
<! -- [If IE 7]>

<! -- If the iebrowser version is "7", use the ie7.css style sheet->

<Link rel = "stylesheet" type = "text/css" href = "ie7.css"/>
<! [Endif] -->

<! -- [If lte IE 6]>

<! -- If the IE browser is smaller than or equal to 6, use the ie.css style sheet. -->

<Link rel = "stylesheet" type = "text/css" href = "ie.css"/>
<! [Endif]->

This differentiates the implementation of CSS by IE7 and IE6 to achieve compatibility. At the same time, the first line of CSS is compatible with other non-IE browsers.


Note: The default CSS style should be located at the first line of the HTML document. All the content for condition annotation judgment must be located after the default style.
For example, if the following code is executed in IE, it is displayed in red, but not in IE. If the condition annotation judgment is placed on the first line, it cannot be implemented. This example shows how to solve the compatibility problem between the web browser and the Internet Explorer.

The code is as follows: Copy code

<Style type = "text/css">
Body {
Background-color: #000;
}
</Style>
<! -- [If IE]>

<Style type = "text/css">
Body {
Background-color: # F00;
}
</Style>
<! [Endif] -->


At the same time, someone will try to use <! -- [If! IE]> to define non-IE browser conditions, but note: condition comments can only be executed in IE browser. This code is not executed in non-IE browser, but not in non-IE browser, it turns a blind eye to it as a comment.

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.