My thoughts about CSS hacks for IE

Published on 05/24/12

This will be short but sweet. I don’t like using conditional comments to target IE. I like to keep my markup as clean as possible. Why would I want to put stuff in my content to cater to a browser that is broken?

I’ve recently discovered to CSS hacks that let me target IE 7 only and IE 7 & 8 only.

To target IE 7 only just put an asterisc in front of the property you are editing:

*width: 96%
*padding: 2%

To target IE 7 & 8 only put a ”\9” at the end of the property you are editing just before the simicolon:

width: 96%\9;
padding: 2%\9;

Neither one of these are valid CSS, but IE recognizes them as such so you can send properties to those browsers specifically to try to fix some of the things that are broken (or alleviate the pain a bit).

My reasoning for this is simple, content (HTML) is all about communication. I want it to be simple, clear, and clean. I don’t even like putting comments in my HTML that are meant for people who look at the HTML source. CSS, on the otherhand, is all about getting down and dirty with specific browsers. We are trying to force browsers to make our content look a certain way. I don’t care what I do in the CSS as long as it works.

Using a bug in IE to work around other bugs is fine by me.


Leave a comment