If I could, I’d give you a special present this christmas – I’d tell you how to make IE on Windows behave like a grown-up browser. Sadly, reality sucks – as does IE on Windows – so I can only offer to share with you a couple of CSS tips to ease the pain of working with that piece of crappy software.
1. Reset browser styles
To start off with the right leg, I suggest you reset the styles to some sensitive defaults, so all browsers will render the page as similarly as possible. To do so, you can use one of the many suggested templates to create a reset.css file and include it before you include any other of your style sheets.
2. Add IE 5.5+ png file support
Angus Turnbull over at TwinHelix has written a nice htc script to bring png images support to IE 5.5+. To use it, simply add the following css code into your ie.css file, which you’ve previously included with IE conditional comments – you do use conditional comments, right?
img, h1, .class-with-png-background-image {
behavior: url(../htc/iepngfix.htc);
}
I won’t go deep into explaining how this works as you can easily find more info on the author’s site. Suffice to say that you need to call the iepngfix.htc file as an ie-only dhtml behaviour attribute on the img element and/or any other element where you may want to use png background images on.
The only problem with this script that I’ve found so far, is that it won’t work with repeating background images.
Also you should make sure that the server is configured to serve .htc files correctly. If the script doesn’t work, all you need to do is to add the following line to your .htaccess file, and you should be good to go:
AddType text/x-component .htc
3. Add IE < 7 custom :hover support
Another annoying IE problem is that it doesn’t support css :hover events on elements other than links. This can be easily solved with another .htc script, this time written by Peter Nederlof and you can download it on the Whatever:hover script page.
This script is even easier to use than the png trick, because all it takes is one line in your ie-specific css file:
body { behavior:url("../htc/csshover.htc"); }
4. “Give layout” to elements
The source of most of Internet Explorer’s bugs comes from an IE-only property called layout. An element can either have layout or not, which determines how an element is rendered by the browser. Most of IE bugs can be squashed by giving layout to the offending element, which is done simply by assigning one of the following properties to that element:
position: absolute [IE 6 & 7]
float: left [IE 6 & 7]
float: right [IE 6 & 7]
display: inline-table [IE 6 & 7]
any width or height value [IE 6 & 7]
zoom [IE 6 & 7]
min-width [IE 7]
max-width [IE 7]
min-height [IE 7]
max-height [IE 7]
overflow [IE 7]
Among these, the most common way to “give layout” to an element – and thus, eliminate the bug – is to assign the following rule:
#the-buggy-element { height: 1%; }
However, if the problem persists, you might want to add a “position” to that element. This fixes the problem more often than not.
#the-buggy-element {
position: relative;
height: 1%;
}
An exhaustive article on having layout can be found at http://www.satzansatz.de/cssd/onhavinglayout.html.
5. Prevent the double margin bug from crumbling your layout
This one has saved me a lot of headaches, because IE 6 has a tendency to double the margins of every element, which has been floated and assigned a left/right margin. To overcome this bug, simply set display: inline on the offending element. This will magically make the bug disappear with no adverse effects on your layout.
If you’ve found these tips useful and your future IE-development experience somewhat more pleasant, I invite you to share your thoughts by commenting below.









January 29th, 2008 at 12:54 am
Great tips. Can’t tell you how much frustration I’ve avoided from #4 alone. Despite the supposed “version targeting,” IE8 will not get here soon enough.
Eric Meyer updated his reset stylesheet recently. It’s my personal preference for resetting, and it’s always my starting point when building a new site.
http://meyerweb.com/eric/thoughts/2008/01/15/resetting-again/
January 29th, 2008 at 8:22 am
Thanks Spoon, I have updated the article link to Eric’s revised reset style sheet.
January 29th, 2008 at 2:48 pm
Thanks for sharing these tips. Very useful!
January 30th, 2008 at 2:12 am
Nice tips! thanks. On an other note, your WordPress Theme is beautiful. I was reading an article on smashing magazine about web design trends, and your sophisticated simplicity looks like it should be the next trend (an not that Grunge ugliness!)
January 30th, 2008 at 3:11 am
These are excellent tips.
January 30th, 2008 at 8:53 am
Regis, thank you, I completely agree with your point of view. I never liked grungy sites, I always strove towards clean and light designs, which involve the minimal amount of graphics as possible.
Sadly I don’t have the time to work on Scarf*oo’s looks at the moment, and it still looks a bit unfinished, but I’ll try to release it to the WP community as time permits to take it to a satisfactory level.
January 30th, 2008 at 7:48 pm
Have you tried using the hover.htc and the pngfix.htc? Either the former works or the latter but not both at the same time.
I reverted to using the hover.htc with the supersleight.js script to solve this problem…
January 30th, 2008 at 8:24 pm
Shane, that is strange. I never had any problems using them simultaneously, in fact I am using them together all the time. Are you sure there is not some other script messing up the behaviour?
See http://www.slovenia.si/css/ie.css for a sample implementation.
February 19th, 2008 at 5:07 pm
Gracias por estos asportes. Son muy utiles a la hora de resolver problemas con CSS.
August 7th, 2008 at 7:28 pm
Start with one of my CSS Layout Cheats and you can eliminate many of these headaches. I have provided a collection of fully cross-browser compliant CSS layout templates to use in your layout design.
November 27th, 2008 at 9:07 pm
In regard to PNG fix, you DO NOT need all of these fancy fixes and htc files.
You only need to apply the Microsoft filter (http://msdn.microsoft.com/en-us/library/ms532969.aspx) in an external style sheet with conditional statements in your header.
Just name the div id and apply the filter to that div:
#myDiv {http://msdn.microsoft.com/en-us/library/ms532969.aspx}
Important Note Regarding Links: if you have links or linked images inside the dive with the filter applied, your links may not work. THE FIX: the div with the filter MUST have positioning and the parent div CANNOT have positioning applied.Just add a generice dive around it and your links will work like magic.
Also, use PNG 32 format and any doc type should work. Just experiment. You cannot use background position or repeat with the filter.
There you have it, an easy and working fix.