好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

css区分ie8/ie9/ie10/ie11 chrome firefox的代码

网站兼容性调试实在令人烦心,现在的网站设计人员真的要比以前费力很多,因为网页代码不再是只需满足一个IE6访问就行,而是要满足N多的浏览器访问 正常 才行。粗略算一下,目前至少要满足如下的浏览器要求:IE8、IE9、IE10、IE11、Ch rom e、Firefox,由于 360 使用的是C hr ome内核,所以满足Chrome基本就满足了360。而IE家族真是一个版本一个样,我说IE怎么这么喜欢折腾呢?这给网页设计师带来多大的麻烦呀!今天,我就把这几个主要浏览器的CSS hack代码汇总一下。

例如现有CSS代码如下:

.divContent{
    background-color: # eee;
}

那么下面我们就来写一下,如何使代码兼容几个主流浏览器。

/* IE8+ */
.divContent{
    background-color:#eee\0;
}
/* IE8、IE9 */
.divContent{
    background-color:#eee\8\9\0;
}
/* IE9 */
.divContent{
    background-color:#eee\9\0;
}

注意,\8\0的写法是错误的,不能试图这样hack IE8。上述代码没有对IE10和IE11分别hack(好像没有对这两个浏览器单独hack的写法),那么IE10和IE11使用的就是IE8+那个样式。

IE家族hack完毕,下面看看如何hack Chrome和Firefox浏览器。

/* Chrome */
@media screen and (- webkit -min-device-pixel-ratio:0) {
    .divContent{
        background-color:#eee;
    }
}
/* Firefox */
@-moz-document url- PR efix() {
    .divContent{
        background-color:#eee;
    }
}

另外,还可以这样hack其他浏览器

/* Chrome 和  opera  */
@media all and (min-width:0){
    .divContent{
        background-color:#eee;
    }
}
/* IE9+ */
@media all and (min-width:0) {
    .divContent{
        background-color:#eee;
    }
}
/* IE10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none)  {
    .divContent{
        background-color:#eee;
    }
}

经过这样hack,网站浏览器兼容性问题就可以完美解决了。

在css中区别ie浏览器和chrome浏览器

/***** 样式 Hack ******/

/* IE6 */
 _color: blue;

/* IE6, IE7 */
 *color: blue; /* 或 #color: blue */

/* 除 IE6 外任何浏览器 */
 color/**/: blue;

/* IE6, IE7, IE8 */
 color: blue\9;

/* IE7, IE8 */
 color/*\**/: blue\9;

/* IE6, IE7 -- 作为 !important 使用 */
 color: blue !ie; /*  !后面的字串可以为任意字串 */

/***** 选择器 Hack ******/

/* IE6 及以下 */
* ht ML  #uno  { color:  red  }

/* IE7 */
*: First -child+html # DOS  { color: red } 

/* IE7, FF, Saf, O PE ra  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (除 IE 6,7 外任何浏览器) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 及以下, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[ XM lns*=""] body:last-child #s ei s { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of -t ype(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webk IT -min-device-pixel-ratio:0) {
 # die z  { color: red  }
}

/* iPhone / webkit 内核移动端 */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}

/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* 除 IE6-8 外任何浏览器 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
 #veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
 #veinticinco,  x:-moz-any-link, x:default  { color: red  }

以上就是css区分ie8/ie9/ie10/ie11 chrome firefox的代码的详细内容,更多关于css区分ie11 chrome firefox的资料请关注其它相关 文章 !

总结

以上是 为你收集整理的 css区分ie8/ie9/ie10/ie11 chrome firefox的代码 全部内容,希望文章能够帮你解决 css区分ie8/ie9/ie10/ie11 chrome firefox的代码 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于css区分ie8/ie9/ie10/ie11 chrome firefox的代码的详细内容...

  阅读:40次