IE conditional comment

IE conditional comment is a non-standard logic statements from Microsoft IE5 start provided, is to be flexible import different html elements for different versions of IE browsers, such as: style sheets, html tags. Obviously the biggest benefit of this method is that part of the solution is compatible with Microsoft's official given by the W3C but also efficacy.

Keywords explanation

lt :就是Less than的简写,也就是小于的意思。

lte :就是Less than or equal to的简写,也就是小于或等于的意思。

gt :就是Greater than的简写,也就是大于的意思。

gte:就是Greater than or equal to的简写,也就是大于或等于的意思。

!:就是不等于的意思,跟javascript里的不等于判断符相同。

Let's take a look at a few examples:

1, only IE to recognize

<!--[if IE]>
 <link type="text/css" rel="stylesheet" href="my.css" />
<![endif]-->

Because only the above IE5 versions began to support IE conditional comments, all "IE only" in order to identify the means "only IE5 or later" in order to identify.

2, in order to identify the specific version only

<!--[if IE 8]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

Identify a specific version of IE, high or low can not. IE8 can identify the cases only.

3, not only to recognize a specific version

<!--[if !IE 7]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

Example IE7 the specific version does not recognize, can identify other editions, of course, in the above IE5.

4, only above a certain version before recognition

<!--[if gt IE 7]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

In the example above only to identify the version of IE7. IE7 is not recognized.

5, is equal to or higher than a specific version can identify

<!--[if gte IE 7]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

Examples IE7 and the higher version can identify.

6, only less than a specific version to recognize

<!--[if lt IE 7]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

Lower than the previous example only version of IE7 in order to identify, IE7 does not recognize.

7, equal to or lower than a specific version can recognize

<!--[if lte IE 7]> 
<link type="text/css" rel="stylesheet" href="my.css" />   
<![endif]-->

Examples IE7 upper and lower versions can be identified.

Special Note:

1, some people will attempt to use - to define the conditions under non-IE browsers, but note <[if IE!]!> : Conditional comments can only be performed in the IE browser, this code is used as a comment in a non-IE browser turn a blind eye.
2, we usually use the comment IE browser different load conditions according to different css, so as to solve the problem of compatibility style. In fact, it can do more. It can protect any code blocks --HTML code blocks, JavaScript code blocks, server-side code ...... look at the code.

<!--[if IE]> 
<script type="text/javascript"> 
 alert("你使用的是IE浏览器!"); 
</script> 
<![endif]-->

Guess you like

Origin www.cnblogs.com/jlfw/p/12632590.html