What are the drawbacks of using PHP to create variables in my CSS stylesheet?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2010-06-01T01:42:30Z Indexed on 2010/06/01 1:53 UTC
Read the original article Hit count: 373

Filed under:
|

One significant drawback of CSS is that one can't use variables. For example, I'd like to use variables to control the location of imported CSS, and it would be awesome to create variables for colors that are used repeatedly in a design.

One approach is to use a PHP file for the CSS stylesheet. In other words, create a "style.php" with...

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

...at the top of the file, and then link to it using...

<link href="style.php" rel="stylesheet" type="text/css" />

...in any file that uses these styles.

So what's the catch? I think it might be performance -- I did a few quick experiments in Firefox/Firebug and as one would expect, the CSS stylesheet is cached, but the PHP stylesheet isn't. So we're paying the price of an additional GET.

The other annoying thing is that TextMate does not syntax highlight properly for CSS in a .php file.

Are there other drawbacks? Have you used this approach, and if so, would you recommend it?

© Stack Overflow or respective owner

Related posts about php

Related posts about css