Mr eel
CSS Hacks - Targeting Internet Explorer
Just about any web professional using pure CSS for layout has probably come across layout bugs. The biggest culprit is Microsoft’s Internet Explorer. No surprise there, other folks have complained about it already.
The only real choice for getting around these bugs are using CSS-hacks. Now there is something of a religious war over using these hacks. Some devs think that since they often mean creating invalid CSS we simply shouldn’t use them. My view is a bit more pragmatic. Hacks are the only practical way of dealing with these bugs, so we should just use them and document their use.
Anyhow, to the subject at hand. Sometimes you want to target specific versions of IE — only have IE apply a particular rule.
The first one is really easy. Just prefix your rule with an underscore. Like so:
_font-size:2em;
All versions of IE will apply this rule. If you wanted to target every version of IE after IE 5, you can use a little comment hack:
font-size/**/:2em;
IE 5 will not apply this rule, but IE 6 will. One thing to look out for though, is that most other browsers would apply this rule as well. So if you wanted to target IE 6 only, you can combine the two hacks:
_font-size/**/:2em;
Easy! Looks like crap, but it works beautifully.
Comments