WEBDOOD.COM

IE CSS backslash 9 hack beats the star hack

by webdood on Aug.23, 2010, under CSS, Software Development

Most folks know about the so-called “star hack” for IE.

However, there are two other varieties of IE-only hacks that are perhaps a bit more useful.

All of these work, in some form or another for IE. I tested them all in various flavors to arrive at my favorite (sic).

You can set up a test harness yourself using this code to see for yourself.

<style type=text/css>
body {
background-color:red;
_background-color:blue;
*background-color:green;
background-color:yellow\9;
}
</style>

  • _ hack WORKS for: IE8 Quirks, IE7 Quirks, IE6
  • _ hack DOES NOT WORK for: IE8 IE8 Standards, IE8 IE7 Standards, IE7 IE7 Standards
  • * hack works for: IE8 Quirks, IE8 IE7 Standards, IE7 Quirks, IE7 IE7 Standards, IE6
  • * hack DOES NOT WORK for: IE8 IE8 Standards
  • \9 hack WORKS for: IE8 IE8 Standards, IE8 IE7 Standards, IE8 Quirks mode, IE7 Quirks, IE7 Standards (all varieties of IE8), IE6

So, in short, if you want an IE CSS hack that works in all flavors of IE, use the backslash-nine hack. That is, just put a \9 after *whatever* css value you are assigning.

Examples
width: 9px\9;
background-color:yellow\9;

etc.

Good luck. I feel this to be quite a discovery.

Shannon Norrell

:, , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

  • A List Apart
  • Dive into HTML5
  • Javascript: The Good Parts
  • QuirksMode.org