CSS hack

1.属性级Hack

_:选择IE6及以下。连接线(中划线)(-)亦可使用,为了避免与某些带中划线的属性混淆,所以使用下划线(_)更为合适。
*:选择IE7及以下。诸如:(+)与(#)之类的均可使用,不过业界对(*)的认知度更高
\9:选择IE6+
\0:选择IE8+和Opera15以下的浏览器

如想同一段文字在IE6,7,8显示为不同颜色,可这样写:

.test {
    color: #c30;          /* For latest Firefox, chrome, Safari */
    color: #090\0;        /* For Opera15- */
    color: #00f\9;        /* For IE8+ */
    *color: #f00;         /* For IE7 */
    _color: #ff0;         /* For IE6 */
}

* 上述Hack均需运行在标准模式下,若在怪异模式下运行,这些Hack将会被不同版本的IE相互识别,导致失效。

 

2.选择符级Hack

* html .test { color: #090; }       /* For IE6 and earlier */
* + html .test { color: #ff0; }     /* For IE7 */
.test:lang(zh-cmn-Hans) { color: #f00; }  /* For IE8+ and not IE */
.test:nth-child(1) { color: #0ff; } /* For IE9+ and not IE */
posted on 2015-09-16 10:26  陶淘  阅读(121)  评论(0编辑  收藏  举报