HTML条件注释用法诠释
注释内容以样式为例,如下:
1、支持所有IE浏览器
<!--[ifIE]>
<linkrel="stylesheet"href="all-ie-only.css"type="text/css"/>
<![endif]-->
2、支持非IE浏览器
<!--[if!IE]>
<linkrel="stylesheet"href="not-ie.css"type="text/css"/>
<![endif]-->
上面是除了IE浏览器外所有浏览器都识别这个样式,另外CSS-TRICKS的《HowToCreateanIE-OnlyStylesheet》一文中提供了另一种写法:
<!--[if!IE]><!--><linkrel="stylesheet"type="text/css"href="not-ie.css"/><!--<![endif]-->
3、仅仅支持IE10
<!--[ifIE10]>
<linkrel="stylesheet"type="text/css"href="ie10.css">
<![endif]-->
4、支持IE10以下版本(IE9以及IE9以下版本)
这种方法是样式表使用在低于IE10的浏览器,换句话说除了IE10以外的所有IE版本都将被支持。
<!--[ifltIE10]>
<linkrel="stylesheet"type="text/css"href="ie9-and-down.css">
<![endif]-->
也可以写成
<!--[iflteIE9]>
<linkrel="stylesheet"type="text/css"href="ie9-and-down.css">
<![endif]-->
前面我们也说过了lt和lte的区别,lt表示小于版本号,不包括条件版本号本身;而lte是小于或等于版本号,包括了版本号自身。
上面这几种方法,使用的是低于(lt)和低于或等于(lte)的方法来判断,我们也可以使用大于gt和大于或等于gte达到上面的效果:
5、高于IE9的版本(IE10以及IE10以上版本)
<!--[ifgtIE9]>
<linkrel="stylesheet"type="text/css"href="ie10-and-up.css">
<![endif]-->
或
<!--[ifgteIE10]>
<linkrel="stylesheet"type="text/css"href="ie10-and-up.css">
<![endif]-->
6、指定多种IE版本
<!--[if(IE6)|(IE7)|(IE8)]>
<linkrel="stylesheet"type="text/css"href="ie6-7-8.css">
<![endif]-->


本文转载自中文网


本文转载自中文网
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h55118.shtml