Home
View
Websites
Add Your Website
General
Forum
Login
Register

Dynamic CSS



Page 1 of 1

Post a reply

Hi
In my new site, I would like to make my CSS dynamic i.e. change the stylesheet based on user preferences.
Is there any way to do this with php?
Just inserting some php code doesn't seem to work.

Cheers

Posted: 22:43 Tuesday 26th May by timphp

Hi
It is possible to use PHP in your CSS.

Save your stylesheet as a PHP file (e.g. end the name with .php) and begin it with:

<?php
header("Content-type: text/css");



End it with:

CSS;
?>


Everything in the middle can be written just as you would a normal stylesheet but you can also have some php code e.g.

$color1 = "#272d5d";

h1 {
display:inline;
color:$color1;
font-size:25pt;
}

You call the stylesheet from your header just as you would normally. You can also send it some variables e.g.:

echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css.php?user_id=$user_id&browser=$browser\" />";

This works really well.
Respond back if there are any issues.

Thanks

Posted: 13:32 Thursday 28th May by Maverick

Initial Posts

All forum postings must conform to the forum rules
Terms of Use - Contact Us - copyright PS Ventures Ltd (2008)