使用媒体查询(写在css里)
一,支持IE10及以上
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
css代码
}
二,支持IE9及以上
@media screen and (min-width:0\0) {
css代码
}
三,支持IE8及以上
@media screen\0 {
css代码
}
四,仅支持IE8
@media \0screen {
css代码
}
五,支持IE8及以下
@media \0screen\,screen\9 {
css代码
}
六,支持IE7及以下
@media screen\9 {
css代码
}
七,仅支持谷歌
@media screen and (-webkit-min-device-pixel-ratio:0) {
css代码
}
使用IE hacks(写在css里)
"_" 是IE6 专有的hack;
"\9" 对IE6-IE10都有效;
"\0"对IE8-IE10都有效;
"\9\0"对IE9-IE10都有效;
background-color:#f00;/*all*/
background-color:#0ff\0;/* ie 8/9 */
background-color:#0f0\9\0;/* ie9 */
*background-color:#00f;/*ie7*/
_background-color:#ff0;/*ie6*/
background-color//:#090;/*非IE*/
background-color:#900\9;/*所有ie*/
优点: CSS hacks 内嵌在普通的 CSS 里面,不会产生更多 HTTP 请求。CSS hacks 内嵌在普通的 CSS 里面,编写时比较方便。
缺点: 它是不标准的产物。内嵌在其他 CSS 中,不便维护。尤其是当 hacks 的数量比较多的时候维护简直是个恶梦。内嵌在其他 CSS 中,即使在非 IE 浏览器中也会被加载,浪费资源。
条件注释(写在html里)
<!--[if IE 6 ]>
< link rel="stylesheet" type="text/css" media="all" href="./ie6.css" />
< ![endif]-->
<!--[if lte IE 8 ]>
<link rel="stylesheet" type="text/css" media="all" href="./assets/css/ie8.css" />
<![endif]-->
<!--[if lt IE 7]>版本小于IE7将看到这行<![endif]-->
<!--[if lte IE 7]>版本小于或等于IE7将看到这行<![endif]-->
<!--[if IE 7]>版本如果是IE7将看到这行<![endif]-->
<!--[if gt IE 7]>版本大于IE7将看到这行<![endif]-->
<!--[if gte IE 7]>版本大于等于IE7将看到这行<![endif]-->
参考文章:
https://blog.csdn.net/mo3408/article/details/80900725
https://blog.csdn.net/cy5849203/article/details/81382891
https://blog.csdn.net/namechenfl/article/details/83029189