Subscribe to RSS Follow me on Twitter
Hi, I'm a web developer and blogger from Russia. My nickname is Dimox.
Sorry for my English, it's not my native. Read more about me and my blog.

Personal CSS Hacks for IE6, IE7, IE8

290110'
Personal CSS Hacks for IE6, IE7, IE8
Written by Dimox

Are CSS hacks an evil? Yes, of course.

But we will use them, while browsers like IE6, IE7 and IE8 will exist and while Microsoft will not create a normal browser, which will stand on equal with modern browsers like FireFox, Safari, Chrome and Opera.

We, web developers, are constantly faced with deficiencies of Internet Explorer, and CSS hacks allow to overcome them in most cases.

In this post I would like to group the personal CSS hacks for each of the 3 popular versions of IE. Most likely you already know the CSS hacks for IE6 and IE7, but for IE8 probably not. Therefore the focus of this article is on a personal CSS hack for Internet Explorer 8.

CSS hack for Internet Explorer 6

It is called the Star HTML Hack and looks as follows:

* html .color {color: #C39;}

This hack uses fully valid CSS.

CSS hack for Internet Explorer 7

It is called the Star Plus Hack.

*:first-child+html .color {color: #66F;}

Or a shorter version:

*+html .color {color: #66F;}

Like the star HTML hack, this uses valid CSS.

CSS hack for Internet Explorer 8

I learned about it from a familiar russian web developer, who’s found it by experimental way. It looks like this:

.color {color: #0FC\0/;}

There are several similar variants of this hack, but this is the easiest. It’s very easy to remember. Just add the \0/ at the end of a CSS rule. This hack must go after the rules for all another browser, i.e.:

.color {color: #777;} /* for all browsers */
* html .color {color: #C39;} /* for IE6 */
*+html .color {color: #66F;} /* for IE7 */
.color {color: #0FC\0/;} /* for IE8, going last */

This hacks does not use valid CSS, therefore I recommend to use a conditional comments.

Demo

I’ve created a simple demo, it displays, what personal CSS hacks works fine for all 3 versions of IE. Take a look.

Category: CSS
Tagged with: , , , , ,

Comments on: "Personal CSS Hacks for IE6, IE7, IE8" (13)

  1. 1

    CSS hacks are never a good solution…

    Of course there is conditional comments but it’s not very usefull with big CSS…
    I prefer this clever use of conditional comments, wich is still improvable like this:
    <!--[if IE 6]><![endif]-->
    <!--[if IE 7]><![endif]-->
    <!--[if IE 8]><![endif]-->
    <!--[if !IE]>--><!--

    What do you think about this?

    • 2

      I would never use this method, because the HTML becomes ugly. Moreover, on my practice I have not met the need for simultaneous connection of stylesheets for all 3 version of IE.

      I don’t see a problem with extra HTTP requests while using conditional comments.

      • 4

        > I would never use this method, because the HTML becomes ugly.
        Ok, I understand

        I make a pastie because Wordpress removes a lot of tags… ;-)

        No problem with extra HTTP requests using conditional comments, it’s just sometimes difficult to maintain CSS with conditional comments because CSS parts are in different files.

  2. 3

    THank you very much.
    It was very helpful for me.

    @Jeremy: against the Non standard rules of IE versions and their inconvenience , it is a great and fast solution indeed.

  3. 5

    I prefert to use this:
    <!–[if IE 6]><![endif]–>
    but everyone has the way the he loves…

  4. 6

    Hello! I saw most of the png image file in the site have failed due to IE 6! you just help me to fix for each browser are not

  5. 7

    Thank for share it, it’s really useful. By the way, it’s ugly but very fast to change some code that mess all our css-fashion code ^^

    Darn, i really hate IE.

  6. 8

    hey guyz this css styles is not working for
    is there something i need to include such as header information
    my html page just contains a single div element

  7. 9
    Bazooka said:

    This will work in IE-Tester (myDebugbar). Conditional not (the <!– thing –>)

  8. 10

    Thanks for this, it works like a charm.

  9. 11

    Hi All..

    Conditional comments are good in a sense to overcome the non-standard problems of IE versions, but there are hidden issues not known to the UI/Web designer when we develop pages with JSF. JSF has got configuration settings in WEB XML file to SKIP comments, so the CONDITIONAL comments never works…! :(

  10. 12

    I came to this page via Thomas Fuchs’s blog and I am still slightly aghast that, when we have a 100% certain way of handling IE ’speshulness’ using conditional comments, people still advocate hacks which can have unforeseen consequences now and in the future.

    All to save a bit of space in the html? Seems fack to brunt to me.

  11. 13

    Good one , All at one place

Leave a comment





Tag Cloud