@import Rule Alternative


We've talked a lot about using @import to bring in stylesheets that Netscape 4 can't see. If you don't want to give NN4 any styles at all (you're a tough customer!) that works just fine.

If you want or need to support NN4, you can create a stylesheet for that browser and bring it in with the <style> tag. Then follow that with an @import stylesheet for all the better behaved browsers.

But something about that solution/hack bothers me - namely, it's not intuitive to have the first style declarations be the exceptions and the later css be the well behaved stuff. I keep changing the wrong stylesheet!

I just finished a new sub-site for a client who has 40% Netscape 4 users, and I was struggling. So what I did was write the main stylesheet for compliant browsers and then I use this javascript to bring in the Netscape 4 exceptions:

if (document.layers)
    {document.write('\074link rel=stylesheet href="nn4.css">')

Since Netscape 4 is the ONLY browser that has document.layers, this works just fine.

Now you ask, what if the user has javascript disabled? Well, Netscape 4 must have JavaScript enabled for there to be any CSS support at all - so you're skipping over no one. Netscape never built true CSS code until version 6 - they just kludged on top of their JSS (javascript style sheets) code.

So, the end result - my "main" stylesheet is the obvious one, and the home for the Netscape 4 exceptions is also obvious. I know this is kind of a fine point, but it's helping me out considerably. It's good to have options.


NOTE rewboss later escaped the leading "<" character for the link tag with "\074" to avoid validator problems caused by using a link tag outside the document's head.