1. 条件注释语句css
<!--[if !IE]><!--> 除IE外均可识别 <!--<![endif]--> <!--[if IE]> 全部的IE可识别 <![endif]--> <!--[if IE 6]> 仅IE6可识别 <![endif]--> <!--[if lt IE 6]> IE6以及IE6如下版本可识别 <![endif]--> <!--[if gte IE 6]> IE6以及IE6以上版本可识别 <![endif]--> <!--[if IE 7]> 仅IE7可识别 <![endif]--> <!--[if lt IE 7]> IE7以及IE7如下版本可识别 <![endif]--> <!--[if gte IE 7]> IE7以及IE7以上版本可识别 <![endif]--> <!--[if IE 8]> 仅IE8可识别 <![endif]--> <!--[if IE 9]> 仅IE9可识别 <![endif]-->
2. CSS hack 写法html
/* 全部浏览器 通用*/ height: 100px; /* IE6 专用 */ _height: 100px; /* IE6 专用 */ *height: 100px; /* IE7 专用 */ *+height: 100px; /* IE七、FF 共用 */ height: 100px !important; /* IE6 7 8 9 10通用 */ height: 100px\9;
(1)*: IE6+IE7都能识别*,而标准浏览器FF+IE8是不能识别*的;浏览器
(2)!important: 除IE6不能识别 !important外, FF+IE8+IE7都能识别!important ;spa
(3)_ : 除IE6支持_ 外, FF+IE8+IE7都不支持_;firefox
(4)\9:全部IE浏览器都识别(IE六、IE七、IE八、IE9)code
.test{ /* 1. */ /* color:#09F\0; 之前是IE8/9, 如今10也支持 */ color:#09F\0/; /* 之前是IE8 only, 如今IE9/10也支持. 如要排除IE9须要使用下面的rule重设IE9样式 */ } @media all and (min-width:0) { /* 2. */ .test{color:red\9; }/* IE9 only, 如今IE10也支持 */ /* Ps:老外的方法都是\0,根本没考虑Opera */ } @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { /* 3. */ .test { color: green; } /* IE10+ */ } :root .test { color:#963\9; } /* 之前IE9 only, 如今10也支持, 优先级高于@media, 优先级过高, 尽可能少用 */
3. 识别IE10htm
1) 特性检测:@cc_onblog
咱们能够用IE私有的条件编译(conditional compilation)结合条件注释来提供针对ie10的Hack:该脚本里面的IE排除条件注释,以确保IE6-9不认可它,而后它功能检测到了名为@ cc_on。在这里:ip
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <!--[if !IE]><!--<script> if (/*@cc_on!@*/false) { document.documentElement.className+=' ie10'; } </script><!--<![endif]--> </body> </html>
用法utf-8
.ie10 .example { /* IE10-only styles go here */ }
IE10支持媒体查询,而后也支持-ms-high-contrast这个属性,因此,咱们能够用它来hack ie10:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { /* IE10-specific styles go here */ }
@media screen and (min-width:0\0) { /* IE9 and IE10 rule sets go here */ }
参考:
http://feilong.org/ie7-ie8-ie6-firefox-css-hack