Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

NN7 doesn't load stylesheets that don't end in .css

A little gotcha to be aware of



11:53 pm on Apr 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Irk.. pesky Netscape.

I just developed a nice little stylesheet chooser in php. The idea was that I could link to the script like this..

<link rel="stylesheet" type="text/css" media="all" href="/styles/selector.php">

It could then check what cookie the user had set and just pipe the correct stylesheet through.

Tested it and it worked just fine in Opera7 and IE6. But I couldn't get it to work on NN7. A little further investigation reveals that unless your external stylesheet ends with .css Netscape will simply ignore it.

This seems very wrong to me - I've already told it the mime type of the stylesheet (

), the file extension should be irrelevant.


3:44 am on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Well, not only do you need text/css in the link to the style sheet, the server must transmit the page as text/css too.

There are two ways to solve the problem. Either, in your .htaccess file, add php as a text/css mime type. Or, better yet since it's a PHP file, make sure that it prints the text/css header before anything else.

The problem has nothing to do with the extension, just that NN7 doesn't receive a true text/css file :)


3:51 am on Apr 3, 2003 (gmt 0)

10+ Year Member

Not so, Graham. I just tested it.
Something else is wrong.

Just specifying the type in the page's HTML is not enough.
The server must return the data with correct type, as well.
check your server documentation.


4:25 am on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Bullseye! You were absolutely right, it was the content-type being sent by the server that was the problem.


header("Content-Type: text/css")
to the php script soon solved the problem.

For the record, the final PHP function looks like this..

function output_stylesheet( $filename ) {
$content = @file( $filename );
$contentlength = count( $content );
header('Content-Type: text/css');
for ( $line = 0; $line < $contentlength; $line++ ) {
print $content[$line];
output_stylesheet( 'default.css' );

Of course now I'll expand it a bit so that it selects from a number of different stylesheets based on a cookie setting. That way I can support multiple stylesheets without waiting for Netscape or IE to work properly with the <link rel="alternate stylesheet"> tag.

Plus it seems like a nicer way to handle browser specific sheets.


Featured Threads

Hot Threads This Week

Hot Threads This Month