CSS hack是指我们为了兼容各浏览器,而使用的特别的css定义技巧。
比如 IE6能识别下划线_和星号*,IE7能识别星号*,当不能识别下划线_,而firefox两个都不能认识。等等
书写顺序,一般是将识别能力强的浏览器的CSS写在后面。下面如何写里面说得更详细些。
如何写CSS Hack
比如要分辨IE6和firefox两种浏览器,可以这样写:
<style>
div{
background:green; /* for firefox */
*background:red; /* for IE6 */
}
</style>
<div>我在IE6中看到是红色的,在firefox中看到是绿色的。</div>
各浏览器CSS hack兼容表:
IE6 | IE7 | IE8 | Firefox | Chrome | Safari | |
!important | Y | Y | ||||
_ | Y | |||||
* | Y | Y | ||||
*+ | Y | |||||
\9 | Y | Y | Y | |||
\0 | Y | |||||
nth-of-type(1) | Y | Y |