Forum Moderators: open
In response to a post I sent yesterday, I was adviced to use no more than 2 style sheets for two kind of browsers. The rest should be done by css hacks. I'm going to try to do that.
However, what happens when a use doesn't have JavaScript enabled? How can I make it pick a style sheet?
here is my script at the moment:
-----------------------------------------------
<script language="JavaScript"><!--
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;
if (browser_type == "Microsoft Internet Explorer") {
document.write("<link REL='stylesheet' HREF='css/ie.css' TYPE='text/css'>");
}
else {
document.write("<link REL='stylesheet' HREF='css/other-browsers.css' TYPE='text/css'>");
}
// --></script>
------------------------------------------------
So if the browser doesn't allow JavaScript, it won't pick any of these style sheets.
If I attach the html page to the two style sheets then it always take the last one in the list.
I hope it makes sense.
Thanks a lot
Simpliest way is to comment out a line if javascript is enabled for example:
No it's not :-)
The simplest way is to use the html element specifically created for the purpose [w3.org]:
<noscript>
<link rel="stylesheet" type="text/css" href="/default.css" />
</noscript>
-B
Unfortunately, <noscript> is not considered valid markup in the <head>. However, all browsers that I have have tested are fine with it.
You're right Kaled - at least, now that you mention it, I recall noscript flunking validation when used in the head of a document. On the other hand, I looked around a bit and found it in use in the head on a valid page of mine. I have no idea why how I found this out, or why it's true, or if it's just a bug in the validator, but wrapping <noscript> elements in <object> elements causes the page to pass validation. On the other hand, <link ... /> inside <noscript> fails anyway so my solution is flawed at best...
;-)
-B
Put your default stylesheet in the head anyway. Javascript always seems to over-ride default stylesheets when the script is in the head (sometimes even misplaced in the body). The other thing is the rule of thumb, if a class is defined with more attributes in one stylesheet then the other then it will use that stylesheet over the less defined.
When will we have both validation and support?
"256 EB of ram huh? When I was a kid we have 2gbs of ram and our operating systems would use the hard drive first anyway and thats how we lived back in the blizzard of 05!" "2gbs of cache grampa?"