tags:

views:

272

answers:

3

for /* IE8 and below */

i can use this color : green\9;

but I need a hack which should only effect to IE8 , not to IE9, IE6 and 7

+11  A: 

Use conditional comments in HTML, like this:

<!--[if IE 8]>
<style>...</style>
<![endif]-->

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.

Palantir
I need hack not conditional
metal-gear-solid
Why do you need a hack? Hacks, by their very nature, should be avoided (except as an absolute last resort).
Dean Harding
You should be able to go a long way by using conditionals (which are a hack themselves, by the way), as they allow you to have a specific code section executed only if a certain version is detected, and that could contain CSS, HTML, JS, ...
Palantir
@Palantir: You're right that conditional comments are a kind of hack, but at least they're "officially" supported and can be targeted directly at a specific version as required, rather than just relying on quirks of the engine to interpret them in different ways.
Dean Harding
@codeka: I fully agree with you
Palantir
Well, lets consider this purely from an academic pov - is there a hack for IE8 only?
James Westgate
Another thing to (slightly) strengthen the argument for a hack is what if there is already a hack for ie7, above a hack for ie6. You would want to keep the hacks together, rather than seperating the ie8 hack away in another place in the code.
James Westgate
A: 

Can you not use the hack you've already shown, and then use an IE7 and below hack to override it?

Damien_The_Unbeliever
*Pleeeeease* don't use hacks! Hacks to override *other* hacks is even worse!
Dean Harding
@codeka - MGS has already insisted in a comment to another answer that he will only use hacks, so I was just going with the flow. If it was me, I'd go with conditionals, as Plantir already answered.
Damien_The_Unbeliever
A: 

Use \0.

color: green\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.

BalusC