|
CSS Tip:
Missing Style Sheets in Netscape
by Tom Dahm,
Chief Operations Officer,
NetMechanic, Inc.
Using linked style sheets is a great way to simplify site maintenance. But if you use this technique be sure you check your links regularly. If you don't, visitors using Netscape Navigator may not be able to load your site at all!
Style sheets are a huge leap forward in Web design, allowing you precise control over the look and feel of your pages. If you work with Style Sheets often enough, sooner or later you'll start reusing the same styles between your pages. You can easily do this by using the LINK tag to tie an external style sheet to your page, like this:
<LINK REL="stylesheet"
HREF="mystylesheet.css" TYPE="text/css">
|
This tag tells the browser to look for a separate file called "mystylesheet.css" that contains a series of style rules. If it finds this file, it applies these rules to your page.
For example, suppose you had the following Web page, called mypage.html:
<HTML>
<HEAD>
<STYLE>
.redtext {color : red}
</STYLE>
</HEAD>
<BODY>
<P CLASS="redtext">
This text should be red.
</P>
</BODY>
</HTML>
|
Instead of defining the style sheet within this page, you could move your STYLE tag into mystylesheet.css and reference it from mypage.html, like this:
mystylesheet.css:
.redtext {color : red}
mypage.html:
<HTML>
<HEAD>
<LINK REL="stylesheet"
HREF="mystylesheet.css" TYPE="text/css">
</HEAD>
<BODY>
<P CLASS="redtext">
This text should be red.
</P>
</BODY>
</HTML>
|
Notice that the file mystylesheet.css doesn't include the STYLE tag itself. Since we told the browser that this file is a style sheet within the LINK tag, we don't need to put the STYLE tag in the file itself. In fact, if we do so, the style sheet won't work properly.
Using the LINK tag makes sense, since it minimizes your site maintenance workload. If you decide to change your site's style, having all your styles in one central file can make life a lot easier. Instead of editing every page in your site, just edit the style sheet and the changes carry forward to every page in your site.
There's one big negative to this approach, though: if you use it, you need to be very, very sure the style sheet file actually exists on your Web site. If you don't, Netscape Navigator will refuse to load your page. Instead, the browser will display the dreaded "404 - File Not Found" error message.
This can be an especially aggravating problem when you first run into it, since it's not obvious that the style sheet is the cause of the problem. Check the browser's Location field; if the style sheet is the cause you'll see its address there, instead of the address of your Web page.
This problem can be hard to spot if you use Microsoft Internet Explorer as your primary browser because MSIE forgives this error. If it doesn't find your style sheet, it loads your page anyway, without using your custom style. You may not get the style you wanted, but at least your page loads.
The best way to prevent this problem is to check your links regularly. Our HTML Toolbox service will tell you if you have missing style sheets.
|