您的位置:首页 > Web前端 > HTML

[多浏览器兼容]IE浏览器HTML条件注释

2015-11-11 22:16 561 查看
IE条件注释,即在标准HTML注释中,加入特殊的IE内核能识别的语法,根据不同的IE版本来解读。IE5开始就支持条件注释,但IE10在标准模式下已经不支持条件注释。

用法:

<!--[if IE]>只有IE才能看到<![endif]-->

<!--[if IE 6]>只有IE6才能看到<![endif]-->

<!--[if lt IE7]>只有比IE7更低(lower than,不包括IE7)的IE才能看到<![endif]-->

<!--[if gte IE7]>只有大于等于IE7 (greater than or equal to)的IE才能看到<![endif]-->

<!--[if (gte IE6)&(lt IE 8)]>只有大于等于IE6,且小于IE8的IE能看到<![endif]-->

<!--[if (IE 7)|(IE6)]>只有IE6和IE7能看到<![endif]-->

可以在中间插入HTML和script,实现对不同浏览器的支持。例如,对低于IE7(不包括IE7)的IE给出升级提示:

<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->


对不同版本的浏览器设置不同CSS:

<!--[if lt IE 7]>      <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->


参考:

[1] 语法示例:http://boohover.pixnet.net/blog/post/12309095-ie-%E6%A2%9D%E4%BB%B6%E5%BC%8F%E8%A8%BB%E8%A7%A3,conditional-comments-%5Bif-ie%5D

[2] 官方说明:https://msdn.microsoft.com/en-us/library/ms537512.aspx

[3] 项目示例:https://github.com/angular/angular-seed/blob/master/app/index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: