CSS hacks – Targetting IE7

A simple hack to target IE7 only:

[code]/* Target IE7 only */
html>body #getquotebox {
*background: url(../images/loginbox-bg.jpg) 10px left no-repeat;
/* end */[/code]

Can be used in cases where conditional comments can’t be, for whatever reason.

5 comments on “CSS hacks – Targetting IE7

  1. There’s actually a hackless way to target any version of IE 7, called the “conditional comment” that is only available to IE, but is completely ignored by all other browsers. It’s a hack in the sense that you’re creating CSS specific to a browser type, but the advantage is that you’ll always write valid CSS.

    Read about its use here:

    What’s great about this technique is that you can write your CSS for Firefox and other compliant browsers, then drop in a conditional comment with a new style block that will override your previous definitions. This makes your base CSS file portable and hackless.


  2. Thanks! This will be the only little tiny bit of code that isn’t valid on my site because I’ve run into a problem in IE that can’t be solved any other way. It’s the one when you center the background in the body with background-position: center; and you center the header div with margin: 0 auto; and it ends up 1 pixel to the left in IE. Very annoying. They need to solve that!

    By the way does this work in previous IE browsers or is it just for IE7?

Leave a Reply

Your email address will not be published. Required fields are marked *