While working on this site,I decided that it would be cool to have the ability to change the color or design of your website. This thought was quickly diminished when I realized that it would mean that I would need to create a new stylesheet for every color option imaginable….ugh….

What I decided to do was to create an use dynamically generated css files. This was a complete revelation to me and I was completely thrilled to discover this, but a lot of sites out there were misleading and made people take things a bit to far to make it work.

These sites would tell people to make a change to their .htaccess file which would then result in any CSS file on your site to not render properly, requiring you to convert them all to PHP, effectivley making WordPress or any generic install worthless on your site because of the extension problems it creates.

To make this work, simply do the following:

If your stylesheet was originaly named stylesheet.css simply rename it to stylesheet.php and add this to the top of your stylesheet:

<?php Header (”Content-type: text/css”);?>

Thats it. SIMPLE! Now ou can perform any php code within your new css file and it should work without a hitch! Here is an example of how a div may be declared:

<?php $textcolor = #FFFFFF;
$bordercolor = #666666;
?>
div {
 color:<?php echo $textcolor; ?>;
 font-size:12px;
 padding-left: 8px;
 border-left:3px <?php echo $bordercolor; ?> solid;
}

No comments yet.

Would you like to login?