March 4, 2004

A Simple CSS Hack to Cover IE

The Modified Simplified Box Model Hack is the best way I've run across to fix the problems with IE5.x/Win. (And that's the majority of the problems I run into) You don't end up hacking up your prime declarations, but rather put in a new selector using the star html selector hack, and combine that with the escape hack.

* html    /* this selector recognized by IE only */
{
  width: ;   /* total width (only for IE5.x/Win) */
  w\idth: ;  /* content width (for other IE) */
}


{
  padding: ;
  width: ;   /* content width (for other browsers) */
}
The first rule is for IE. The nice part is that the second listing, using the escape hack (\), overrides IE 6, but not 5.5 and prior.
Keep in mind that the backslash cannot appear before the first letter of the property since IE5.x/Win understands that. Furthermore, the backslash cannot appear before the letters a to f, and A to F, and numerals 0 to 9 since doing so will turn those letters or numerals into hexadecimal numbers.
The second rule (plain ole' selector) is recognized by all CSS-aware browsers. Because of specificity , the order of these rules doesn't matter. Specificity counts the number of ID attributes, other attributes and pseudo-class, and element names in the selector. So, if you have the same selectors, but one is declared a little more specific, that is the one that will apply. All in all, this is the most elegant system for hacking my CSS I've found yet.
Post Info

Tagged As CSS

Comments are Open (1)

Posted at 09:15 AM

Comments

Xian

My favorite fix for IE5.x at this point is the mid-pass filter. It has the added bonus of keeping any and all ie5.x rules in a separate file.

http://tantek.com/CSS/Examples/midpass.html

It works by importing a ie5.x only stylesheet. This is great for me because I've taken to only linking one filter CSS file to my pages, and using that file to import the needed stylesheets. And the midpass CSS is just another one in the file.

Some advantages to the linked-filter stylesheet are that having the main CSS linked and not imported fends off the flash-of-unstyled content that some browsers show. Also other CSS files (for print or other media types) can be added easily while only changing one file - a bonus for static sites.

If this was worded awkwardly, I apologize.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu