10 Dirty Internet Explorer CSS Hacks You Might Not know

Introduction

Disclaimer: The intention of this article is not to encourage to apply this hack to your web projects but to understand what have been using by other web designers/developers. The best way to solve Internet Explorer's CSS layout issue is - create different style sheets for different versions of Internet explorers.

Alright, have ever found yourself in this situation, you were trying to update an existing old website, opened CSS file and you saw something that you think it's typo from previous CSS coder - but it's not. There was a CSS file I was trying to update and I saw some asterisks, underscores appear randomly as a prefix in some attributes. Did some search on Google and found out it's Internet explorer hacks!

So, the main purpose of this article, is not encourage you to use hacks, but to understand what hacks have been using by others so whenever you update someone else's project you can interpret the CSS file better. :) Alright, I have collected 10 of them start from IE8 to........ IE5.0!

1. IE 8

 
.color {color: #f00/;}

2. IE 7

 
*+html .box {background:#fff;}
*:first-child+html .box {background:#fff;}

3. IE 7 and below

 
*:first-child+html {} * html {}

4. IE 7 and below

 
.box {
	*background: #f00;	
}

5. IE 6 only

 
.box {
	_background/**/:/**/ #f00;	
}

6. IE 6 only

 
.box {
	_background: #f00;	
}

7. IE 6 only

 
*html .box {background:#fff;}

8. IE 6 and below

 
.box {
	_background: #f00;	
}

9. IE 5.5 only

 
.box {
	_background:/**/ #f00;	
}

10. IE 5.0

 
.box {
	_background/**/: #f00;	
}

Sources

If you want to read more about each hacks, please follow these links:

Show Some Love, Spread This Post!

11 comments

PBT Mon, 13th December 2010 Yep, knowing what they do would just make too much sense, and save everyone a LOT of time... DUH.
Reply
dougwig Thu, 18th November 2010 For IE7 and below I like the "!ie" hack:

.smallText { font-family:Arial; font-family:Tahoma !ie }

I believe !anything will work but !ie is nice and explanatory
Reply
Andy G Thu, 18th November 2010 ie9 should be standards compliant. *should* be (astrick pun not intended)
Reply
Maurizio Mangione Wed, 17th November 2010 IMHO the best way to solve Internet Explorer's CSS layout issues is to learn to write standard code. You really don't need different stylesheet or hacks to build a website that works.
Reply
Thoams Wed, 17th November 2010 Great list !

I think there are two times the hack :
.box {
_background: #f00;
}

I recommand to use this other hack for IE8 and below :
.box {
background: #f009
}

Have a good day !
Thomas.
Reply
Chris Tue, 16th November 2010 Is it just me, or are #6 and #8 exactly the same? They can't be both "IE 6 Only" and "IE 6 and below". Not that it really matters because there's pretty much no one out there using versions below 6 anymore.
Reply
Jason Tue, 16th November 2010 Good post, but how about an explanation of what these do or what they are.

Personally, I find using hacks to whip IE into shape are fine. It's a terrible browser that doesn't conform to standards and if I can limit the time it takes me to fix problems with it, I'll use hacks every time.
Reply
Vaibhav Gupta Tue, 16th November 2010 impressive man... chrres :)
Reply
Elijah Manor Mon, 15th November 2010 Nice, but hopefully I won't have to use ;) What are IE9 only and IE9 and below?
Reply
shani Mon, 16th May 2011 hey there, did you get any answers for your question for css hack for ie9 only and ie9 and below?
Kevin Liew Mon, 16th May 2011 I will recommend IE Conditional Comments:
http://www.quirksmode.org/css/condcom.html

Leave a comment

Have something to say? Drop a comment! No HTML tags are allowed in the comment textfield.

Advertisement