IE7 Hacks

Microsoft has fixed much of the bugs that plagued IE6 and in the process removed the filters we used to target Internet Explorer in our CSS. As Lord God Martha would say, this is a good thing.

However, there will be a time when you need to send a rule to IE7 and not to IE6. Or perhaps you need to send a rule to IE7 and to IE6. I’ve put together a test page of IE6 hacks to see what IE7 doesn’t walk right past. I’m condensing the test page into the paragraph below.

Luckily, there is a loophole for us and we can use this for “offroad use only.” Why am I using this silly description? Because you and I need to move beyond hacks. Place browser specific (IE) in conditional comments or use a serverside script to place a class on the HTML or body (HTML class=”ie6″ ) to target these browsers in your main CSS file.

However, these hacks will let you develop your CSS on the fly and fix your issues before going the proper route.

Test Paragraph (condensed version of test page)

this is the test paragraph to see how IE7 will handle hacks

  • IE7 Beta2 understands #wrap>p.borderfun and applies correct color.
  • IE7 Beta2 ignores * HTML p.borderfun styles.
  • IE7 Beta2 recognizes the * hack.
  • IE7 Beta2 ignores the underscore hack.
  • In Firefox, Safari, and Opera, you should see a red border. In IE7, you should see a black border. In IE6, you should see a pink border.

How to use this

If you need to send something to IE6 and nothing else: use the underscore attribute hack (_border:1px solid pink;) If you want to send something to IE7 AND IE6, use the *attribute hack (*border:1px solid black;). If you want to send something to IE7 and NOT IE6, use a combination (*border:1px solid black; _border:1px solid pink;).

A call to arms

Get out there kids and begin removing your * HTML rules. Place those suckers in a conditional commented CSS file or at least begin replacing them with the underscore hack. When it comes time to tune for IE7, you’ll have less work to do.

— This was originally published on tdrake.net


Posted

in

, , ,

by

Tags:

Comments

3 responses to “IE7 Hacks”

  1. Heri Avatar
    Heri

    Excellent, exactly what I was looking for on Google. Thanks.

  2. Pete Avatar
    Pete

    Just what i was looking for. Just an adaption though:

    If you want to just attack IE7 and not have to then assign something for IE6 you can assign the element with an attribute selector. i.e.

    instead of:

    #myDiv{*border:1px solid black;_border:1px solid pink;}

    do this to only assign IE7

    div[id=”myDiv”]{*border:1px solid black}

    no need to give IE6 a value too!

  3. […] tip is from Last Child, an excellent resource on CSS. This tip is really cool because it is lightweight and […]

Leave a Reply

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