来源:http://www.duitang.com/static/csshack.htmlcss
各游览器经常使用兼容标记一览表:html
标记 | IE6 | IE7 | IE8 | FF | Opera | Sarari |
---|---|---|---|---|---|---|
[*+><] | √ | √ | X | X | X | X |
_ | √ | X | X | X | X | X |
\9 | √ | √ | √ | X | X | X |
\0 | X | X | √ | X | √ | X |
@media screen and (-webkit-min-device-pixel-ratio:0){.bb {}} | X | X | X | X | X | √ |
.bb , x:-moz-any-link, x:default | X | √ | X | √(ff3.5及如下) | X | X |
@-moz-document url-prefix(){.bb{}} | X | X | X | √ | X | X |
@media all and (min-width: 0px){.bb {}} | X | X | X | √ | √ | √ |
* +html .bb {} | X | √ | X | X | X | X |
游览器内核 | Trident | Trident | Trident | Gecko | Presto | WebKit |
注意点:web
网上不少资料中经常把!important也做为一个hack手段,其实这是一个误区。!important经常被咱们用来更改样式,而不是兼容hack。形成这个误区的缘由是IE6在某些状况下不主动识别!important,以致于经常被人误用作识别IE6的hack。但是,你们注意一下,IE6只是在某些状况下不识别(ie6下,同一个大括号里对同一个样式属性定义,其中一个加important 则important标记是被忽略的,例:{background:red!important; background:green;} ie6下解释为背景色green,其它浏览器解释为背景色red;若是这同一个样式在不一样大括号里定义,其中一个加important 则important发挥正常做用,例:div{background:red!important} div{background:green},这时全部浏览器统一解释为背景色red。)浏览器
Hack应用情境(一)ssh
适用范围:IE:6.0,IE7.0,IE8.0之间的兼容ide
实例说明:ui
实例代码:url
.bb{ height:32px; background-color:#f1ee18;/*全部识别*/ .background-color:#00deff\9; /*IE六、七、8识别*/ +background-color:#a200ff;/*IE六、7识别*/ _background-color:#1e0bd1;/*IE6识别*/
}
/*一个用于展现的class为bb的div标签*/ < div class ="bb"></ div >
Hack应用情境(二)spa
适用范围:IE:6.0,IE7.0,IE8.0,Firefox之间的兼容firefox
实例说明:
实例代码:
.bb{ height:32px; background-color:#f1ee18;/*全部识别*/ background-color:#00deff\9; /*IE六、七、8识别*/ +background-color:#a200ff;/*IE六、7识别*/ _background-color:#1e0bd1;/*IE6识别*/
} .bb, x:-moz-any-link, x:default{background-color:#00ff00;}/*IE7 firefox3.5及如下 识别 */ @-moz-document url-prefix(){.bb{background-color:#00ff00;}}/* 仅firefox 识别 */ * +html .bb{background-color:#a200ff;}/* 仅IE7 识别 */
/*一个用于展现的class为bb的div标签*/ < div class ="bb"></ div >
Hack应用情境(三)
适用范围:IE:6.0,IE7.0,IE8.0,Firefox,Safari(Chrome)之间的兼容
实例说明:
实例代码:
.bb{ height:32px; background-color:#f1ee18;/*全部识别*/ background-color:#00deff\9; /*IE六、七、8识别*/ +background-color:#a200ff;/*IE六、7识别*/ _background-color:#1e0bd1;/*IE6识别*/
} @media screen and (-webkit-min-device-pixel-ratio:0){.bb{background-color:#f1ee18}}{} /*safari(Chrome) 有效 */ .bb, x:-moz-any-link, x:default{background-color:#00ff00;}/*IE7 firefox3.5及如下 识别 */ @-moz-document url-prefix(){.bb{background-color:#00ff00;}}/*仅firefox 识别*/ * +html .bb{background-color:#a200ff;}/* 仅IE7 识别 */
/*一个用于展现的class为bb的div标签*/ < div class ="bb"></ div >
Hack应用情境(四)
适用范围:IE:6.0+,FireFox:2.0+,Opera 10.0+,Sarari 3.0+,Chrome全兼容
实例说明:
实例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312"/>
<style type="text/css">
/***************************************** 各游览器兼容CSS **********************************************/ .bb{height:32px;background-color:#f1ee18;/*全部识别*/ background-color:#00deff\9; /*IE六、七、8识别*/ +background-color:#a200ff;/*IE六、7识别*/ _background-color:#1e0bd1/*IE6识别*/} @media screen and (-webkit-min-device-pixel-ratio:0){.bb{background-color:#f1ee18}}{} /* Safari(Chrome) 有效 */ @media all and (min-width: 0px){ .bb{background-color:#f1ee18;/*opera and Safari(Chrome) and firefox*/ background-color:#4cac70\0;}/* 仅 Opera 有效 */ }{} .bb, x:-moz-any-link, x:default{background-color:#4eff00;/*IE七、Firefox3.5及如下 识别 */} @-moz-document url-prefix(){.bb{background-color:#4eff00;/*仅 Firefox 识别 */}} * +html .bb{background-color:#a200ff;}/* 仅IE7 识别 */
/* 通常状况下 咱们区分IE7 只用 +background-color 配合 _background-color 就好了 若是必须写 .bb, x:-moz-any-link, x:default 这样的代码区分 Firefox3.5及如下 则谨记此写法对IE7也有效,故在其中要再重写一次 +background-color 或者使用 * +html .bb{background-color:blue;} 方法仅对 IE7 有效。可以使用 @-moz-document url-prefix(){} 方法独立区分全部 firefox */ .browsers td{width:8%;text-align:center;padding:8px;}} .browsercolor{color:#333;font-size:18px;font-weight:bold;} .ie6{background-color:#1e0bd1} .ie7{background-color:#a200ff} .ie8{background-color:#00deff} .firefox{background-color:#4eff00} .opera{background-color:#4cac70} .other{background-color:#f1ee18;} #tipTable td,#tipTable th{border:1px solid black;width:56px;height:16px;text-align:center;} #wordTable td{margin-left:8px;} #firefoxTip{display:none;} #firefoxTip, x:-moz-any-link, x:default{display:block;/*IE7 firefox3.5及如下 识别 */+display:none/*再区分一次IE7*/} @-moz-document url-prefix(){#firefoxTip{display:block;/*仅 firefox 识别 */}} #ChromeTip{display:none;} @media screen and (-webkit-min-device-pixel-ratio:0){#ChromeTip{display:block;}}{} /* safari(Chrome) 有效 */ @media all and (min-width: 0px){#ChromeTip{display:none\0;} /* 仅 Opera 有效 */ }{}
</style>
</head>
<body>
<table class="browsers" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>IE6</td>
<td></td>
<td>IE7</td>
<td></td>
<td>IE8</td>
<td></td>
<td>Firefox</td>
<td></td>
<td>Opera</td>
<td></td>
<td>Safari(Chrome)</td>
<td></td>
</tr>
<tr class="browsercolor">
<td class="ie6">IE6</td>
<td></td>
<td class="ie7">IE7</td>
<td></td>
<td class="ie8">IE8</td>
<td></td>
<td class="firefox">Firefox</td>
<td></td>
<td class="opera">Opera</td>
<td></td>
<td class="other">Safari(Chrome)</td>
<td></td>
</tr>
</table>
<div class="bb">
<span style="display:none;display:block\0;display:none\9;">Opera的辨别色是深绿色,Opera游览器很时髦么。</span >
<span id="firefoxTip">Firefox的辨别色是浅绿色,Firefox是很强大的游览器。</span >
<span id="ChromeTip">Safari和Chrome的辨别色是金黄色,Safari和Chrome使用的都是Webkit内核</span >
<!--[if IE 8]>IE8的辨别色是蓝色,新版IE8的功能但是很多呢。<![endif]-->
<!--[if IE 7]>IE7的辨别色是紫色,IE7还能够凑合着用!<![endif]-->
<!--[if IE 6]>IE6的辨别色是红色,不过,IE6但是有点落后了!<![endif]-->
</div>
</body>
</html>