PDA

View Full Version : a link to change the style(sheet)


gpopguru
05-08-2004, 07:13 PM
How do you make a link that will change the stylesheet of your page? I know it's possible because they do it on CSS Zen Garden (http://www.csszengarden.com/) . I tried to copy whatever they had, but I don't really know what I'm doing, so that didn't turn out too well. I have something like:
<!-- try to change the stylesheet for page.php -->
<a href="mypage.com/page.php/?cssfile=096.css">test page</a>

Could someone explain this a little better to me??

gsnedders
05-08-2004, 07:27 PM
I typed up one here a while back, done in PHP, it's at: http://www.codingforums.com/showpost.php?p=181635&postcount=6

Just ask here if you have any questions about it.

me'
05-08-2004, 07:31 PM
How do you make a link that will change the stylesheet of your page? I know it's possible because they do it on CSS Zen Garden (http://www.csszengarden.com/) . I tried to copy whatever they had, but I don't really know what I'm doing, so that didn't turn out too well. I have something like:
<!-- try to change the stylesheet for page.php -->
<a href="mypage.com/page.php/?cssfile=096.css">test page</a>

Could someone explain this a little better to me??The way the cZG does it is a bit different to the way it's normally done. It uses php (a programming language executed on the server - a serverside language) to change the stylesheet. It's just as easily done without, however, so here's how it's 'normally' done:<link rel="stylesheet" href="normal.css" type="text/css" />
<link rel="alternate stylesheet" href="alternate.css" type="text/css" />
<link rel="alternate stylesheet" href="alternate2.css" type="text/css" />
...
Then, you need functionality to switch between the stylesheets. Liorean has written a most excellent object-orientated (or as close as Javascript gets) stylesheet switcher, here (http://liorean.web-graphics.com/scripts/themeswitch.html).

gpopguru
05-08-2004, 07:51 PM
thanx for your help:thumbsup: personally, I'm not a big fan of j-script. I like to use PHP instead.

gpopguru
05-08-2004, 08:27 PM
I typed up one here a while back, done in PHP, it's at: http://www.codingforums.com/showpost.php?p=181635&postcount=6

Just ask here if you have any questions about it.

I'm a little new to PHP, so how do you link to it? Like, suppose I had a link that said something like "Change to Style2." How would I make it change the style of the current page?

me'
05-08-2004, 08:31 PM
Well, a good idea is to pass the url of the stylesheet you want to use in the URL, then echo this:
[pass address of stylesheet in url, eg http://example.com/ex.php?sshref=/img/example.css]<html>
<head>
<style type="text/css">
@import "<?php echo (isset($_GET['sshref']) ? $_GET['sshref'] : '/img/default.css') ?>"
</style>
</head>
<body>

<h1>Hello World!</h1>

</body>
</html>

gpopguru
05-08-2004, 09:38 PM
I tried it your way me' and it does the exact same thing that it did when i tried it Error404's way. The page shows up, but it doesn't apply the stylesheet. See for yourself. www.mygpop.net/stuffing/history.php my stylesheet is www.mygpop.net/stuffing/modern.css or 096.css

an example of what it should look like with modern.css applied is at www.mygpop.net/history.php nevermind the images for now.


UPDATE: thanks to Error404, I found that the problem was that I used src="whatever" instead of href="whatever. thanx error404, and thanx to everyone else too.