Reprinted: http://blog.csdn.net/wangchixiao/article/details/42172825
Usually the advantage of WEB is that it can be cross-platform , but there is an alternative in this world , that is , the IE browser. In the usual HTML design, sometimes it is necessary to use some Hack methods for the presentation difference of IE . Conditional comments are one such tool.
Conditional comments are " patents " of IE browser , which means that we can embed a special tag fragment for IE in HTML to solve the performance difference between IE and other browsers. Conditional comments were introduced after IE5 , and all attempts to use conditional comments for browsers lower than IE5 ( <IE5.0 ) are invalid. At the same time, please note that Microsoft no longer supports conditional comments for IE10 and above browsers , so please do not add conditional comments for IE browsers >= IE10 .
In HTML , comments are usually formatted like this :
- <!--Comment content-->
And the conditional annotation is like this :
- <!--[if IE 8]>
- <linkhref=”ie.css” rel=”stylesheet”/>
- <![endif]-->
In the above example , the conditional comment will load a special style sheet for IE series browsers whose version is less than or equal to IE8 .
Conditions available for conditional annotations are :
1, lte (less than or equals to, less than or equal to )
<!--[if lte IE 6]><![endif]-->
2,lt(less than, less than )
<!--[if lte IE 6]><![endif]-->
3, gte (greater than or equals to, greater than or equal to )
<!--[if gte IE 6]><![endif]-->
4,gt(greater than or equals to,大于)
<!--[if gt IE 6]><![endif]-->
5, a specific version of IE, such as IE 6 IE 7 IE 8
<!—[if IE 6]><![endif]-->
6, Exclude version !
<!—[if !IE 6]><![endif]-->
Use conditional comments to add some specific fallback code for IE browsing. For example, when users use browsers before IE8 , they can add a piece of code to the page as follows
- <!—[if it IE 8] > < p > Your browser version is too low, please use Firefox, Google, or a browser with a version greater than IE8 </ p > <![endif-- >
Although conditional comments are unique to IE, when targeting IE series browsers, the above code can simplify some of the code for judging browsing types and versions ( this seems to be one of the rare benefits of conditional comments ) .