IE 下的条件注释(Conditional Comments)
IE的有条件注释是一种专有的(因此是非标准的)、对常规(X)HTML注释的Miscrosoft扩展。顾名思义,有条件注释使你能够根据条件(比如浏览器版本)显示代码块。尽管是非标准的,但是有条件注释对于其他所有浏览器作为常规注释出现,因此本质上是无害的。有条件注释在Windows上的IE5中首次出现,并且得到了Widnows浏览器所有后续版本的支持。
IE的有条件注释及其有效,而且非常容易记住。主要的缺点是这些注释需要放在HTML页面中,而不是放在CSS中。这样,当你不需要这些东西,或者有所更改的时候,就需要维护很多的地方。
基本用法:
<!--[if IE]>此内容只有IE可见<![endif]--> <!--[if IE 6.0]>此内容只有IE6.0可见<![endif]—>
条件注释能被IE判断是什么版本的浏览器,并在符合条件的情况下显示其中的内容,从IE5.0到7.0都支持注释功能,而且版本号精确到小数点后4位:
<!--[if IE 6.1000]>此内容只有IE6.1可见<![endif]—>
条件注释支持的操作符包括:
Operator | Description |
IE | represents Internet Explorer; if a number value is also specified, it represents a version vector |
lt | less than operator |
lte | less than or equal to |
gt | greater than |
gte | greater than or equal to |
! | the NOT operator |
() | subexpression operator |
& | the AND operator |
| | the OR operator |
true | evaluates to true |
false | evaluates to false |