<!DOCTYPE html>
<html>
<head>
<title>Css Hack</title>
<style>
.element
{
width:300px;
height:300px;
background-color:blue; /*All*/
background-color:red\9; /*all ie*/
background-color:yellow\0; /*ie8*/ *background-color:pink; /*ie7 and ie6*/
+background-color:pink; /*ie7*/
_background-color:orange; /*ie6*/
}
:root #test { background-color:purple\9; } /*ie9*/ .element,x:-moz-any-link { background:url(llq.gif) 90px -80px no-repeat;} /*firefox*/
x:-o-prefocus, .element{ #test {background-color:black;} } /*opera*/
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;} } /*chrome and safari*/
</style>
</head>
<body>
<div class="element">test</div>
</body>
</html>
上面这段代码大家可以直接copy出来,保存成html在各浏览器试试。下面我来分析下:
background-color:blue; 各个浏览器都认识,这里给firefox用;
background-color:red\9;\9所有的ie浏览器可识别;
background-color:yellow\0; \0 是留给ie8的,但笔者测试,发现最新版opera也认识,汗。。。不过且慢,后面自有hack写了给opera认的,所以,\0我们就认为是给ie8留的;
+background-color:pink; + ie7定了;
_background-color:orange; _专门留给神奇的ie6;
:root #test { background-color:purple\9; } :root是给ie9的,网上流传了个版本是 :root #test { background-color:purple\0;},呃。。。这个。。。,新版opera也认识,所以经笔者反复验证最终ie9特有的为:root 选择符 {属性\9;}
@media all and (min-width:0px){ #test {background-color:black\0;} } 这个是老是跟ie抢着认\0的神奇的opera,必须加个\0,不然firefox,chrome,safari也都认识。。。
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;} }最后这个是浏览器新贵chrome和safari的。
@-moz-document url-prefix() { .element{/*style for firefox only*/}}
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {.element{/*style for opera only*/}}
没有评论:
发表评论