Design Shack showcases inspiring web design, alongside resources and tutorials for you to succeed in the same way. It is brought to you by David Appleyard, a freelance designer who is available for work.
Placing multiple colour or font schemes on your website blog is often an excellent addition, and it can help to customise your look and feel. It’s easy to add multiple stylesheets to your blog, and ensure that the user’s selection is stored on their computer so the style remains the same on each page.
You need to download the following file, and make sure that it is included in all the pages you’d like to run the style switcher.
tagGo to the area in your index.php source code, just before the tag. Enter the following line of text, to ensure that the javascript file is included correctly:
1 | <script type="text/javascript" src="styleswitcher.js"></script> |
Make a copy of your main style sheet, and alter the colours and layout to create the new colour scheme for your website. Rename the new style sheet along the lines of “style-orange.css”. Do this as many times as required (you can always add more later).
For the main, default stylesheet, enter the following just after the line we added above including the javascript file. This ensures that this is the stylesheet that loads when the page is opened for the first time.
1 | <link rel="stylesheet" type="text/css" href="style.css" title="default" /> |
For all the other stylesheets you have created, enter a line such as the following, changing the name of the colour for each style sheet you have added. Repeat it for all your additional styles.
1 | <link rel="alternate stylesheet" type="text/css" href="style-orange.css" title="orange" /> |
For each stylesheet you have created, just enter a link similar to the following. This will cause the selected stylesheet for the page to change to the one clicked on in the link. The setActiveStyleSheet(’orange’); part needs to be altered to reflect the title of the alternate style sheets you specified before.
1 | <a href="/" onclick="setActiveStyleSheet(’orange’); return false;">Orange</a> |
It’s also a good idea to enter a link similar to the following, in case a visitor wants to switch back to the default stylesheet:
1 | <a href="/" onclick="setActiveStyleSheet(’default’); return false;">Default</a> |
So there you have it - an easy and straight forward way to add additional style sheets to your website, giving your visitors a choice as to which colour or layout they see. This method can also be used for adding a high contrast accessible style sheet, which is something recommended for any website.
Hope it’ll work as smoothly as it looks.
Thank you very much.
man…it looks so simple…thanx
this is not workin..
I can’t get it to work either. When I click on a link to change the style sheet it sends me to my web host home page. I’ve tested it in firefox, opera and ie6.
It will work after changing the inverted commas to apostrophes - at the setActiveStyleSheet(’orange’) function around the default/color name - have fun
Just waiting to use this on my site. I have been making CSS based sites since last 6 months, but never tried this. I am currently re-designing my own site, and would use most of the things you mentioned in this website.
Working perfect, follow thom23’s advice and that’s it!
Nice job! Simple and straight to the point. :)
I have followed all the advise and when I click to change the page style it goes to my local host page :s any way around this?
The site im making is saves a .php
Not work in IE7, only Firefox and opera…
[...] Style Sheet Switcher es un interesante Script que permite que nuestros usuarios puedan cambiar la hoja de estilo de nuestro blog por otra hoja de estilo alternativa que previamente diseñaremos. Dando así la posibilidad de que elijan las tonalidad que mas les agrade a la hora de navegar en nuestro sitio. [...]
Thx, work’s fine with ”-fix.
Tested and working as intended in ff3, ie6-8