homepage Welcome to WebmasterWorld Guest from 54.166.122.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
NN7 doesn't load stylesheets that don't end in .css
A little gotcha to be aware of
grahamstewart

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 834 posted 11:53 pm on Apr 2, 2003 (gmt 0)

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 (type="text/css"), the file extension should be irrelevant.

 

DrDoc

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



 
Msg#: 834 posted 3:44 am on Apr 3, 2003 (gmt 0)

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 :)

ricfink

10+ Year Member



 
Msg#: 834 posted 3:51 am on Apr 3, 2003 (gmt 0)

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.

grahamstewart

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 834 posted 4:25 am on Apr 3, 2003 (gmt 0)

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

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

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

[pre]
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' );
[/pre]

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved