什么是 CSS Hack ?
一般来说针对不同的浏览器写不同的 css 就是 CSS Hack,Hack主要针对 ie 浏览器
CSS Hack 常见的形式有三种:
- 属性 Hack
- 选择符 Hack
- 条件注释 Hack
1、条件注释 Hack
<!--[if IE]>
<span> 只能在 IE 浏览器中看到我 </span>
<![endif]-->
条件注释只能在 IE 浏览器才能执行,在其他浏览器中都是被当成注释。可以载入不同的 CSS 、JS 、HTML 和服务器代码等等
2、属性Hack
.test{ color:#090\09; /* For IE8+、FF */
*color:#f00; / * For IE7 * /
_color:#ff0; /* For IE6 */ }
属性级Hack:
比如IE6能识别下划线“”和星号“”,
IE7能识别星号“”,但不能识别下划线” ”,而firefox两个都不能认识。
background-color:red9; 9所有的ie浏览器可识别;
background-color:yellow0; 0 是留给ie8的,
3、选择符Hack
* html .test{color:#090;} /* For IE6 and earlier */
*+html .test{color:#ff0;} /* For IE7 */
.test{color:#f00;} /* For IE8+ and not IE */
IE6能识别 *html .class{}
,IE7能识别*+html .class{}