IE 浏览器条件注释详解(html中的注释)

1. 只允许 IE 解释执行 ,IE 5 之后版本加入了对条件注释的支持,所以 IE 5 以上方可使用注释。

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

以上代码当浏览器为 IE 时,加载样式表 style.css,当然代码可以为 CSS、HTML、JavaScript 等多种。


2. 只允许特定版本 IE 解释执行,可以通过注释,只允许 IE 5、IE 6、IE 7、IE 8 中某个版本能解释,方便与对某一版本进行独立控制。

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

以上代码当浏览器版本为 IE 7 时,加载 style.css 样式表。


3. 只允许非特定版本 IE 解释执行,通过注释排除 IE 5、IE 6、IE 7、IE 8 中某个版本的执行,方便与对非特定版本的 IE 进行独立控制。

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

以上代码当浏览器版本不是 IE 7 时,加载 style.css 样式表。


4. 只允许高于或低于特定版本 IE 解释执行,限定高于或低于某个版本的 IE 方可执行,控制的灵活性较大。

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

以上代码当浏览器版本高于 IE 7 时,加载 style.css 样式表。其中在代码 “<!–[if gt IE 7]>” 中,”gt” 表示高于,如果换成 “lt”,则表示小于,相应的,”gte” 表示大于等于,”lte” 表示小于等于。


转载自 :http://www.mangguo.org/ie-explorer-conditional-comment-detail/


原文地址:https://www.cnblogs.com/hdchangchang/p/3965407.html