Forum Moderators: not2easy
Can this be done through external css calls and how do I format the on page links so the user can change the style?
My goal is to have one master style sheet, and then alternative ones that replace color and background attributes to change the flavor of the users surfing experience.
<link rel="stylesheet" href="default.css" type="text/css" title="Default Style"
media="all" />
<link rel="alternate stylesheet" href="blue.css" type="text/css"
title="I Got the Blues!" />
<link rel="alternate stylesheet" href="gray.css" type="text/css"
title="Business Gray Please!" />
It was fairly easy to do and since I'm working with exact same layout and just a change in color schemes, the changes to the css files were minimal. I've got five styles that the user can choose from and it's a pretty cool feature.
Now I'm going to take that concept and apply accessbility to the various stylesheets. This is just too much fun! ;)
I am thinking about switching to server-side stylesheetswitchers (PHP), which would work in any browser, but also would force a reload of the page and result in ugly urls.
Anyway while we are at it, just to clarify the alternate stylesheets a bit more: There are three different types of stylesheets:
- persistent (used no matter what)
- preferred (used as the default, but replaced, if an alternate stylesheet is used)
- alternate (not applied on page load, only when selected)
The best way (i.e. most compatible way) to assign css-files to be one of the types mentioned is with the rel- and title-tag. So the peristent shoudl not have a title tag, while the preferred should have it:
<!-- Persistent -->
<link type="text/css" rel="Stylesheet" href="always.css" /><!-- Preferred -->
<link type="text/css" rel="Stylesheet" href="default.css" title="whicheverTitleYouWant" />
<!-- Alternate -->
<link type="text/css" rel="Alternate Stylesheet" href="other.css" title="anotherTitleYouCanChoose" />
I'm using the preferred/alternate method. Cookies are also used to maintain the users last selection.
<link rel="stylesheet" href="/css/browns.css" type="text/css" />
<link rel="alternate stylesheet" href="/css/blues.css" type="text/css" title="Blues" />
<link rel="alternate stylesheet" href="/css/pinks.css" type="text/css" title="Pinks" />
<link rel="alternate stylesheet" href="/css/reds.css" type="text/css" title="Reds" />
<link rel="alternate stylesheet" href="/css/greens.css" type="text/css" title="Greens" />
[edited by: pageoneresults at 10:32 am (utc) on May 29, 2003]
/* This is the persistent stylesheet, no title. */
<link rel="stylesheet" href="/css/browns.css" type="text/css" />
/* These are the alternate stylesheets, note the titles. */
<link rel="alternate stylesheet" href="/css/blues.css" type="text/css" title="Blues" />
<link rel="alternate stylesheet" href="/css/pinks.css" type="text/css" title="Pinks" />
<link rel="alternate stylesheet" href="/css/reds.css" type="text/css" title="Reds" />
<link rel="alternate stylesheet" href="/css/greens.css" type="text/css" title="Greens" />
And this is the html for the links...
<a href="#" onclick="setActiveStyleSheet('Blues'); return false;">Change Style to Blues</a>
<a href="#" onclick="setActiveStyleSheet('Pinks'); return false;">Pinks</a>
<a href="#" onclick="setActiveStyleSheet('Reds'); return false;">Reds</a>
<a href="#" onclick="setActiveStyleSheet(''); return false;">Browns</a>
<a href="#" onclick="setActiveStyleSheet('Greens'); return false;">Greens</a>
Right now I've left the title empty for the Browns as that is the default style sheet. Everything appears to be working but I'm guessing that there may be a 404 being generated when that call is made to the Browns style sheet.
If I give my persistent stylesheet a title, then the cascade does not work with the alternate stylesheets.
So you would have
/* This is the persistent stylesheet, no title. */
<link rel="stylesheet" href="/css/onlylayout.css" type="text/css" />
/* This is the preferred stylesheet with title. */
<link rel="stylesheet" href="/css/browns.css" type="text/css" />
/* These are the alternate stylesheets, note the titles and rels. */
<link rel="alternate stylesheet" href="/css/blues.css" type="text/css" title="Blues" />
<link rel="alternate stylesheet" href="/css/pinks.css" type="text/css" title="Pinks" />
<link rel="alternate stylesheet" href="/css/reds.css" type="text/css" title="Reds" />
<link rel="alternate stylesheet" href="/css/greens.css" type="text/css" title="Greens" />