Recently in CSS Category

Where's the love for conditional comments?

| No TrackBacks

I hate trying to resolve CSS and Javascript conflicts between web browsers. What I hate even worse is going about it in an "unclean" way.

Conditional comments for IE have been around a long time and I haven't really seen too many people (if any) using them for resolving style bugs. Check out what I do on every web site I build.

<link href="/public/css/style.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="/public/css/style-ie.css" />
<![endif]-->
<!--[if lt IE 7]>
    <link rel="stylesheet" type="text/css" href="/public/css/style-ie6.css" />
<![endif]-->

Note that I normally don't bother with IE 5.5, but this could work for that as well. With these CSS links in place, I can simply expect a normal, sane style sheet to be included on well-behaved browsers, a special style sheet for IE7, and an even more "special" style sheet for IE6. Since these are declared in order of insanity, (from least to greatest) I can simply copy style declarations from my original style sheet, override whatever I need to, and keep everything squeaky clean.

There's my solution. If anyone reading still uses CSS hacks, I would love to know why. It may be something I just don't "get."

Powered by Movable Type 4.21-en

Recent Comments

  • Leandro Nuñez: Hey, thanks for the great share. Is there a way read more
  • Justin: cool plugin. how would you go about creating then wiring read more
  • Anil: Nice plugin. I wanted to add some validation and stop read more
  • reigel: look cool... It would be okay if it can validate read more
  • glompix: @derby We actually do use Subverison for our version control, read more
  • derby: I use xperl, dominos, and titan bar to customize my read more
  • derby: Thanks for the script. I was looking for some AJAX read more
  • A. burton: how do you set up a search for events created read more
  • NANERPUSS: LEXINGTON GOONTUCKY :hfive: read more
  • Matt: This is a great walkthrough. I am also using the read more