代码改变世界

IE9 Only CSS Hack

2011-11-23 14:38  俊俊+  阅读(215)  评论(0)    收藏  举报

Apparently my subconscience was still working on the problem for me. Suddenly had an idea, well, a question, actually:

"Whats new in IE9?"

I'll tell you whats new, media query expressions. Specifically, the and (min-width:value) part.

Update (18 May 2011): Mathias Bynens (twitter) posted a comment explaining that the :root selector is new in IE9! The @media all and (min-width:0) part as been removed in favor of this method. Thanks Mathias!

 

Update (13 June 2011): This hack is a bit mysterious as doesn't work on all properties (like background, for instance) and isn't considered "safe" (yet). Checkout Mathias' post on safe css hacks.

Ta-freaking-Da:

 
1
2
3
4
5
6
7
8
9
10
11
12
13
#element {
    color:orange;
}
#element {
    *color: white;    /* IE6+7, doesn't work in IE8/9 as IE7 */
}
#element {
    _color: red;     /* IE6 */
}
#element {
    color: green\0/IE8+9; /* IE8+9  */
}
:root