No Hacks, Please!
It may seem to the beginner that using conditional comments is more work, more code or (my favorite) people say that conditional comments are proprietary. Let me explain why you should favor condcoms over hacks.
Lies About Conditional Comments
Condcoms are more work
Even though it may seem so when you use condcoms for the first time, in actuality it is less work, especially when you are trying to debug your stylesheet.
Condcoms require more code
That is a complete lie. With condcoms you need to write CSS irrelevant code only once. When using hacks you have to write ugly and lengthy code for each rule, and it often includes fixing your fix in yet another browser.
For those who want to argue that this influences separation of content from presentation. I will say that you should be using condcoms in the external file and including your
<link> elements with SSI or with any server side scripting language. Including two CSS files instead of one does not relate to separation of content from presentation in any way.
Conditional comments are proprietary
First of all, let me laugh deeply at people who use this excuse. Yes, they are proprietary, but:
- They appear as regular HTML comment to anything that doesn't support them, thus no harm is done.
- What makes your hacks less proprietary? Useless garbage code that is used to target specific browsers.
Conditional comments require extra files
Yes, they do! I don't see why this is such a matter. Sure, having extra HTTP requests might not be such a good idea, especially on sites with a lot of traffic, but personally I very rarely need more than one IE specific file.
Also, I find that having all of your IE specific code in a separate file eases up the coding process. If IE doesn't like your page, just switch to the IE file tab in your favorite editor and you have all your current fixes on one screen. Of course the amount depends on the size of the website, but properly coded sites won't need more than a few lines for hasLayout or improper unit calculations.
I agree that in some instances using hacks instead of conditional comments would be a better, if not the only choice. Moreover, in my opinion if you have only one or two IE specific fixes it is much saner to use hacks instead. It is all up to you. You have your options, you make your own choices. Just keep in mind that:
- Hacks rely on browser bugs which are likely to be fixed eventually.
- Conditional comments are vendor provided method for using IE specific code, thus are unlikely to be removed any time soon.
- Every browser sees your hacks. There is a possibility that a next version (or even the current one) of browser XYZ will choke on them.
- Only IE interprets code in conditional comments. With a separate IE file, other browsers will not even download it.
- Hacks are not verbose about their function. Yes you can put a bunch of comments and make it even more of a mess.
- Conditional comments provide version matching which enables author to easily target versions that need a specific code. Which means that with condcoms you can be sure the code will not be parsed in the next version of IE unless you want to. That is not true with hacks, since, as I have said, they rely on bugs and bugs may live longer than the next release of the browser.