For Internet Explorer 8 (IE8) I'd like to use the following CSS:
color : green;
I would like to apply a hack which only affects IE8, not to IE9, IE6 and 7.
For Internet Explorer 8 (IE8) I'd like to use the following CSS:
color : green;
I would like to apply a hack which only affects IE8, not to IE9, IE6 and 7.
For IE8 native browser alone:
Can you not use the hack you've already shown, and then use an IE7 and below hack to override it?
Use
\0
.I however do recommend conditional comments since you'd like to exclude IE9 as well and it's yet unpredictable whether this hack will affect IE9 as well or not.
Regardless, I've never had the need for an IE8 specific hack. What is it, the IE8 specific problem which you'd like to solve? Is it rendering in IE8 standards mode anyway? Its renderer is pretty good.
So a recent question prompted me to notice a selector set hack for excluding IE 8 only.
.selector, #excludeIE8::before {}
will cause IE 8 to throw out the entire selector set, while 5-7 and 9-11 will read it just fine. Any of the::
selectors (::first-line, ::before, ::first-letter, ::selection
) will work, I've merely chosen::before
so the line reads accurately. Note that the goal of the fake::before
selector is to be fake, so be sure to change it to something else if you actually have an element with the IDexcludeIE8
Interestingly enough, in modern browsers (FF 45-52, GC 49-57, Edge 25/13) a bad
::
selector eats the entire selector set (dabblet demo). It seems that the last Windows version of Safari (and LTE IE 7, lol) doesn't have this behavior while still understanding::before
. Additionally, I can't find anything in the spec to indicate that this is intended behavior, and since it would cause breakage on any selector set containing:::future-legitimate-pseudoelement
... I'm inclined to say this is a bug- and one that'll nibble our rears in the future.However, if you only want something at the property level (rather than the rule level), Ziga above had the best solution via appending
\9
(the space is key; do NOT copypaste that inline as it uses an nbsp):Side note, I feel like a dirty necromancer- but I wanted somewhere to document the exclude-IE8-only selector set hack I found today, and this seemed to be the most fitting place.
Use conditional comments in HTML, like this:
See here: http://www.quirksmode.org/css/condcom.html
You can test for IE versions reliably and also be sure other browsers won't be confused.
There are various ways to get a class onto the HTML element, identifying which IE version you're contending with: Modernizr, the HTML 5 Boilerplate, etc - or just roll your own. Then you can use that class (eg .lt-ie9) in a normal CSS selector, no hack needed. If you only want to affect IE8 and not previous versions, put the old value back using a .lt-ie8 selector.