I think, therefore I blog

Targeting IE Using CSS Hacks

By , 29 May 2007

Targeting IE Using CSS Hacks

Without a doubt, one of the most difficult aspects of web design is achieving cross-browser consistency. The problems generally arise because of defects in the browsers' implementation of CSS, defects in their interpretation of the standards (think the box-model bug), or gaps in their coverage of the standards - some of which are gaping.

The gaps aren't as troublesome as the defects though. Where there are defects, or disagreements in either the interpretation or implementation of CSS, you often need to apply different styles depending on which browser is being used. Here are some simple but handy CSS hacks that you can use to target styles to specific browsers.

Targeting IE Using CSS Hacks

Actually, all you really need are hacks to target IE6 and IE7, since most other browsers play ball. IE6 can be targeted with the underscore hack by simply prepending an underscore to the style. IE7 fixed this defect, but still responds to the asterisk hack, which is exactly the same but uses an asterisk instead of an underscore.

div.example {
   width: 300px;    /* applied in all browsers     */
   *width: 350px;   /* applied to IE6 and IE7 only */
   _width: 360px;   /* applied to IE6 only         */

Although people warn about hacks falling over as browser defects are fixed, this hasn't presented much of a problem for me. Generally, it seems that the defects which the hack is meant to fix gets resolved and this makes the hack redundant anyway. Microsoft are also pretty good about not fixing their defects too. I wouldn't expect the underscore hack to stop working in IE6 any day soon.


About Roger Keays

Targeting IE Using CSS Hacks

Roger Keays is an artist, an engineer, and a student of life. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

Please visit https://RogerKeays.com/blog/targeting-ie-using-css-hacks to add your comments.

Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?