1 reply [Last post]
Chad_Cross's picture
Long Beach, CA
Last seen: 13 years 23 weeks ago
Long Beach, CA
Joined: 2005-07-21
Posts: 58
Points: 0

Howdy, I wasn't sure if this fell in into the CSS styling or layout sections so I have posted it here.

I am interested in changing CSS dynamically. Basically, I had the idea of creating a control panel so I could have a site admin set the background colors of different elements, creating different themes. Just like the front page of this site actually. Only, I would like the site admin to make the changes, and they show up the same on everyones screen instead of giving every user the options.

Is there a way to have a CSS file pull styles or attributes from a database?

I will continue to look on Google for ways of accomplishing this but I thought the great people here might have some insight.


Tyssen's picture
Last seen: 7 years 31 weeks ago
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

changing styles dynamically

You can actually have your page use a PHP file for its CSS. You copy your CSS into a PHP file and add this to the top:

ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";

then link your page to the CSS.php file. So, then, as your CSS file is now a PHP, you can include in it whatever sort of logic you want.

Here's a bit more info about gzipping your CSS:


How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference