« Previous entry | Next entry » Browse > Snippets

Skip to comments (4) CSS for IE only
Posted by Erik on Nov 01 2005 @ 17:18  :: 3168 unique visits

Today I came across a usefull method to only show CSS to IE.
I alwais used the e > e { } trick to only execute some CSS to Firefox but now I can also do it the other way around.

I am not talking about conditional comments.
This is different in the following ways:


The method is called the "Underscore Hack":

CODE: CSS
body {
  background: green; /* executed by FireFox/Other normal browsers */
  _background: red/* executed by IE only */
}


There is only 1 disadvantage and that is that the CSS won’t validate anymore.

4 comments posted so far
Add your own »

1. On Nov 02 2005 @ 11:57 Jos wrote:

For an overview of CSS hacks, check out this page.

It's much better to avoid hacks though.

2. On Nov 02 2005 @ 15:22 guest wrote:

<style type="text/css">
  /* standards compliant CSS goes here */
<!--[if IE]>
  /* IE - only CSS goes here */
<![endif]-->
</style>

3. On Nov 04 2005 @ 14:43 toran wrote:

<3
...

4. On Nov 06 2005 @ 01:35 lsm_rulez wrote:

Hhhmmm, never seen this hack before. I agree that we should avoid hacks where possible. I still prefer to use the html>body method because it works in current browsers and, according to the info on IE7, will work in IE7 to boot.

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: