Internet Explorer 8 CSS hacks

Mar25
  • Share

Difficulty: ★★☆☆☆

Last friday Internet Explorer 8 was launched as an official release. This will mean that lots of people will finally use it.

Allthough IE8 passed the ACID2 test, again a new browser can be painfull for the webdeveloper to support multi-browsers.
Luckily there are also IE8 CSS stylesheet hacks:

.test{
     color:blue;
     //color:red;
}

With this hack, all browsers will skip the line with color: red, since this is a comment line (before the property). Except for Internet Explorer. IE8 ignores it, and just change the color to red, while other browsers keep the color blue.

But there is more!
IE8 Standards-Mode Only:

.test { color /*\**/: blue\9 }

All IE versions, including IE8 Standards Mode:

.test { color: blue\9 }

Another trick, to make css styles for IE8 only, is by using conditional comment tags in your HTML:

<!--[if gte IE 8]>
      <style type="text/css">
      body {
       color: #0000ff;
       background-color: #000000;
      }
      </style>
<![endif]-->

6 Responses to “Internet Explorer 8 CSS hacks”

Hello, and thank you for a great source of information!

The IE8-standard hack “.test { color /*\**/: blue\9 }” now also applies to IE7 =/

Sven Almgren on April 22nd, 2009 at 7:49 AM

Hello, thanks a lot, The code which you given works fine me!!!!
#.test { color /*\**/: blue\9 }

Pradeep V S on July 9th, 2009 at 11:04 AM

thanks a lot to share this fixs.!

kndlaria on August 13th, 2009 at 11:54 PM

It’s Use Full

Rajee on September 21st, 2009 at 5:20 AM

Cheers mate, this is a wicked wicked hack, a great help :D

Tudor on October 14th, 2009 at 4:35 PM

thanks so much. just what i needed! :)

bluestrikesagain on March 2nd, 2010 at 12:20 PM

Leave a comment