Skip to Navigation

Structuring your CSS – A Slight Revision

With the forthcoming release of a new version of Internet Explorer, many of the hacks and workarounds used by site developers to target individual browser flaws and serve custom CSS are going to stop working. The developers of IE 7 have themselves warned that a number of the hacks, (such as those discussed previously on this site) will no longer work and should be avoided. They’re suggestion as a replacement method is to use conditional comments, something we have been implementing at Cimex for some time.

The following is an example in using conditional comments to serve CSS files to different versions of Internet Explorer. One caveat is that Internet Explorer 5 (Mac OS X) does not make use of these conditonal comments and, if you are still supporting it, will need to be served CSS using an alternative method.

  1. <link rel="stylesheet" ... href="list.css" />
  2. <!--[if IE 5]>
  3. <link rel="stylesheet" ... href="ie-5-win.css" />
  4. <![endif]-->
  5. <!--[if IE 6]>
  6. <link rel="stylesheet" ... href="ie-6-win.css" />
  7. <![endif]-->
  8. <!--[if IE 7]>
  9. <link rel="stylesheet" ... href="ie-7-win.css" />
  10. <![endif]-->

The above code provides a default “list.css” stylesheet which in my template serves a stylesheet to reset all elements to their default values and a stylesheet for the site itself. Conditional comments supplement this with a specific CSS file for each browser version under Microsoft Windows. The Mac OS X version is served its CSS file from within the “list.css” file.

This method has worked for my testing of the preview of IE 7 beta 2. That doesn’t mean it will work in the final version.

Leave A Comment

Some HTML is allowed, (general text-formatting and linking). Images and complex HTML is not. Abide by the rule ‘I shall think before I speak’ and you’ll be fine.


More About This Entry

The entry ‘Structuring your CSS – A Slight Revision’ was posted in the ‘long’ category on the 2nd June, 2006.

There are no comments on this entry.

You Might Like This

A randomly selected something that you might enjoy. I may have been involved with some of them.

Flickrshow


Stay Up To Date

There are a number of RSS feeds that you can subscribe to if you want to stay up to date with this site.