June 18th, 2001, 08:57 PM
PHP and CSS
I was wondering how I can include different css files.
For example, want a visitor to be able to click on a link that would load the same page, with a different css file. Sort of like picking skins.
Can anybody help me? I'd be very grateful!
June 18th, 2001, 11:04 PM
For your links' href attribute, which is your php script, include a query sting like this:
Then in your php script do this:
if ($css == style_1)
else if ($css == style_2);
June 19th, 2001, 01:02 AM
Thank you so much! One question - does the code have to go in a certain place, or can it go anywhere?
June 19th, 2001, 01:19 AM
That's an html question: where would you normally have the text in the css file? The include() function just replaces itself with the text contained in the file you are including as if you had typed it there yourself.
How about inside the <head> tags and between some <style> tags?
Last edited by 7stud; June 19th, 2001 at 01:23 AM.
June 19th, 2001, 06:48 AM
Though the other answers to this are also correct, another approach to this is through the use of JS.. most of the modern browsers can change css style sheets without reloading the document.
You can see examples of this at:
They use such things as form buttons, to change the style of a page.
Naturally the PHP approach can do this as well, only PHP will have to reload the page. Granted, you could couple the use of a cookie, so your visitor could actually return to your site, using the same style they selected previously.
Pro's and Con's.. the first method I mention, does require JS being enabled.. not really a concern much these days..
I dunno.. I like the PHP idea far better