IE6 & IE7 Inline CSS Hacks

This page details an inline CSS hack for Internet Explorer 6 and 7 on Windows.

The best idea, however, would be to serve a separate stylesheet for each browser you’re hacking to.

Storing it here for my own posterity, these are inline CSS stylesheet hacks for Internet Explorer 6 and 7. Using these, you can add specific rules that are shown only to those two browser trainwrecks.

/* Show only to IE7 */
*:first-child+html [selector] {
	background: red;
}

/* Show only to IE6 */
* html [selector] {
	background: red;
}

Replace [selector] in the above two examples, to color that elements background red. Example selectors could be body, #my_id or .my_class.

There’s also a good list of inline hacks here.

5 thoughts on “IE6 & IE7 Inline CSS Hacks”

  1. adam says:

    it’s pretty rare that I need to hack inline CSS for IE. I generally use conditional comments to include a stylesheet

    
    
  2. Joen says:

    I took the liberty of wrapping your code in a pre container.

    Yeah having a dedicated IE stylesheet is definately the cleanest and most forwards compatible way to go. However, sometimes you just want to take the shortcut and do the ugly hack. Those times, the above ones are good.

  3. Bramick says:

    Noted.

    I too use a dedicated IE stylesheet. Gotta love IE.

  4. gareth says:

    really drop ie6 support already. ie7 is good enough that i no longer have to do any hacks. Safari gives me more grief.

  5. Sorin Roiban says:

    Thank you for posting this.

Comments are closed.