I know it shouldn't be done, but I just want a quick fix for now and that will give me time to find a proper fix for this.
How can I target IE8 alone using CSS because I've tried appending \9
such as:
margin:100px\9;
However, it also affects IE9 and I don't want that because on IE9 the whole site looks fine.
This should work only in IE9 (and probably newer versions as well):
It is because
:root
pseudo class is not implemented in versions prior to IE9 (see http://msdn.microsoft.com/en-us/library/cc351024%28v=vs.85%29.aspx).From the HTML5 Boilerplate and originally from Paul Irish:
Change your <html> tag to this:
Then IE8 will add a .ie8 class to the html tag. Same for all the other versions of IE. You can then do:
Edit: Removed the no-js class, and please update the lang="" attribute to your language. Thanks, eyelidlessness.
There is three ways to do this,
IE Conditional Comments
IE conditional comment is probably the most commonly used to fix the IE bugs for specific versions (IE6, IE7, IE8). Below are some sample code to target different versions of Internet Explorer:
CSS Rules Specific to Explorer (IE CSS hacks)
Another option is to declare CSS rules that can only be read by Explorer. For example, add an asterisk (*) before the CSS property will target IE7 or add an underscore before the property will target IE6. However, this method is not recommended because they are not valid CSS syntax.
Conditional HTML Class
The third option, which was founded by Paul Irish, is to add an CSS class with the IE version to the HTML tag by using IE conditional comments. Basicially, it checks if it is IE, then add a class to the html tag. So to target specific IE version, simply use the IE class as the parent selector (eg. .ie6 .box). This is a clever way and it doesn't cause any validation errors.
You can use root function
:root #element { color:pink \0/IE9; } /* IE9 + IE10pp4 */
hack only on IE