Previous Message
Next Message

Re: [css-d] Why don't my alternate stylesheets work in Moz?

Sent by Liorean on 25 October 2002 22:10


At 15:59 2002-10-25 -0500, Dougal Campbell wrote:
>I've got some alternate style sheets set for my homepage (url below). But 
>when I'm in a Moz-based browser (tried NS6.2 and 7.0), and choose one of 
>them from the "View/Use style" menu, it doesn't work.
>
>My Javascript style switching works fine.
>
>Semi-related question. In my Halloween theme, the color for visited links 
>in the blog entries isn't getting set like I want in Moz, but they look 
>correct in IE. Any ideas why?

In short, they don't work because of a small logical mistake on your behalf.

You first write
   <link rel="stylesheet" type="text/css" href="halloween.css" />
   <link rel="alternate stylesheet" type="text/css" href="/new2col.css" 
title="Standard" />
   <link rel="alternate stylesheet" type="text/css" href="/halloween.css" 
title="Halloween" />
   <link rel="alternate stylesheet" type="text/css" href="/xmas.css" 
title="Christmas" />
Then you have your style switcher add yet another style through js, 
looking, for example, like this:
   <LINK href="/new2col.css" type=text/css rel=stylesheet>
(parsed HTML by ie6)


What the correct, parsed structure (or at least a better one) for this 
really would look like, is rather something like:
   <link type="text/css" rel="Stylesheet" href="/new2col.css" title="Standard">
   <link type="text/css" rel="Alternate Stylesheet" href="halloween" 
title="Halloween">
   <link type="text/css" rel="Alternate Stylesheet" href="" title="Christmas">
(there's a few issues with some ieMac versions that require capital letter 
on rel attribute)

When you then switch styles, you could either chose to change the 
'disabled' value of the corresponding 'document.styleSheet' collection 
member, or set the cookie and reload the page from scratch, dynamically 
writing the rel attributes to specify what stylesheet to use.


For a nice prewritten style switching mechanism, try my ThemeSwitcher 
<http://members.evolt.org/liorean/scripts/themeswitch-t.html>.
(I could also provide you with a few other, easier-to-manage systems that 
doesn't work in IE because of lack of support in the less usual stylesheet 
declaration mechanisms.)

// Liorean
Previous Message
Next Message

Message thread: