« Previous entry | Next entry » Browse > Snippets

Skip to comments (7) CSS for IE only
Posted by Erik on Nov 01 2005 @ 17:18  :: 7827 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.

7 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.

5. On Apr 18 2009 @ 09:45 Valencia wrote:

A good quality piece of work done. I liked the way you wrote the code. I will surely use it after my 640-802 Exam for Cisco Certified Network Associate (CCNA) and 350-001 Exam. These exams are going to be held in the upcoming month. I am going for the 70-290 Exam. But first I will go for Cisco CCNA Exam due to its great importance. After the above three exams there are also many choices of exams available such as 70-640 Exam for TS: Windows Server 2008 Active Directory, Configuring and 70-649 by Microsoft. Once again thanks for the nice work.

7. On Oct 29 2009 @ 22:41 guest wrote:

Well, this forum has certainly gone to spammer hell.

Add a new comment

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