Logo

Battling with IE – 4 CSS methods

27.03.08

Recently I have come to the realization that I spend so much time in production that I rarely get to search for things that would be useful, big picture resources/learning for future projects. Basically, I’m bad at keeping up with where CSS and HTML are going. And since I am trying to really push myself to have better skills to contribute to not just my current position, but the world at large, I have found a bunch of great resources.

I have to admit that having a blog and wanting to write well researched and thoughtful articles has really contributed to this. I’m still brewing my last critique of Safari 3.1, and in the process of doing research around this have discovered quite a bit of cool stuff (by the way, my writing still sucks, I use words like stuff too much). So I thought I would list a few way to deal with IE issues.

  1. Eric Meyer is the man, and give us this bit of code to break some of the major issues you will run into with IE. You can see them at his Reset Reloaded article, which I found on this webiste, Keys to Consistent CSS. Here’s the code in case you are too lazy:
    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, font, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-weight: inherit;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline;
    }
    /* remember to define focus styles! */
    :focus {
    outline: 0;
    }
    body {
    line-height: 1;
    color: black;
    background: white;
    }
    ol, ul {
    list-style: none;
    }
    /* tables still need 'cellspacing="0"' in the markup */
    table {
    border-collapse: separate;
    border-spacing: 0;
    }
    caption, th, td {
    text-align: left;
    font-weight: normal;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
    content: "";
    }
    blockquote, q {
    quotes: "" "";
    }

    ******Update*******

    The above is the old version of the reset. Eric Meyer has a new version of the browser reset, posted Jan ’08.

  2. Another great resource is Dean Edwards IE7 JavaScript library, which fools anything less than IE7 into thinking its IE7. Initially I thought this was awesome. Then I realized it made me lazy. Then I thought it was too big. Now I’m so good, I don’t need it (which is partially true). Version 2 has gotten much smaller, but is still in Beta.
  3. Hacks. As much as I love them, they create invalid CSS. You can use _ before your propertiess to target IE6, and * before them to target IE7 (which also targets IE6 by the way), or both to create properties that affect both:

    /* Target IE 6 and below*/
    #maincontent {
    width: 400px;
    _width: 410px;
    }
    /* Target IE7 and below */
    #maincontent {
    width: 400px;
    *width: 410px;
    }
    /* Target IE6 and IE7 separately. ***Make sure to put the IE6 ("_") property second*** */
    #maincontent {
    width: 400px;
    *width: 410px;
    _width: 415px;
    }

    Let me be absolutely clear, I do not endorse hacks, but I have been known to use them in a pinch (a fact that I am not proud of).
  4. And here’s my preferred method, Conditional Comments, which you can use to have specific stylesheets for different browsers. Make sure you put these after your global stylesheet(s) so they properly override the styles.

2 Comments on “Battling with IE – 4 CSS methods”

  1. 1

    This is definitely an article I wished I had all together while working through the kwirks of IE. I’ve found that blueprint css framework also gives you a great base of styles and markup to work with that help stay away from IE problems. Blueprint is a great resource and you can pick and choose what pieces of it to use to some extent, great stuff.

    Otherwise I’ve been thinking about some standard widget on pages that will let the web community get rid of IE a little quicker than Microsoft would hope. I know they are preparing IE8 to be really standards compliant, but as always, who wants to wait for them? We have standards compliant browsers, Safari 3 nightlies now pass the acid 3 test 100/100 so IE should really just be unsupported and it’s us web developers who can start that… So here’s the idea…

    A tiny little JS include that anybody can throw in their page that shows little boxes somewhere for browsers. You would “light up” the browsers you support and leave IE greyed out if your site doesn’t support it. The JS would also include a lightbox that pops up letting old IE users or IE users in general know that their browser is “not supported” and that they need to upgrade or preferrably, use a real browser (with links for them to get em). I have a feeling the web community is going to force this before microsoft ever gives up. It’s a method some hate but I like the idea of the folks on the internet telling MS that we won’t wait for their crappy products any longer.

    Jason Martinez said at 21.21 on March 27th, 2008
  2. 2

    Excellent points Jason. I read an article somewhere about a movement to put “Get a real browser” button linking to Firefox, but I can’t support making it hard for IE users to actually use the internet. Then we become just as bad as them. IE is digging their own grave… See my upcoming rant on Safari 3.1 (part 3).

    Also, there’s a couple places for people like you and me to promote well built browsers to those who might need them. Check out http://www.spreadfirefox.com/ and http://browsehappy.com/. Both great sites.

    And thanks for the tip on Blueprint. I’ll have to check that out.

    t.nels said at 22.41 on March 27th, 2008

Leave a Reply