Ideas, solutions, & thoughts on creating for the box.
Using PHP as CSS
February 10, 2010
So often I've wished that css had variables built in. I've finally come across the solution.
- Save your stylesheet as .php
- Call the stylesheet as usual
<link ... href="styles.php"> - At the top of styles.php, in a php block, put
header('Content-Type: text/css'); - Do cool stuff:
<?php $brightCol = '#cc0000'; ?>
div.foo {
background: <?php echo $brightCol; ?>;
}
This is better than just putting the server generated styles on the page, because the browser caches an external stylesheet, but will need to read styles on the page each time the page is loaded.
Like this? Let me know; it makes me happy.