When writing CSS,you will find yourself repeating information a lot, which is always a bad thing in programming. CSS 2 lacks constants, which would allow us to define a value once and refer to it many times. Instead, we are forced to repeat the actual value many times, making updating CSS a process that is prone to errors.
Also, in order to reduce the number of connections a client must make to the server, it’s necessary to place all CSS in a single file. But this may mean that you end up with a lot of possibly unrelated CSS in a single file, making it difficult to navigate while you’re developing. There are times when it’s simply handier to have lots of small files instead of one big file, but it’s just not practical for download by your visitors.
These two problems can be resolved by loading your CSS through PHP. Instead of serving the CSS file directly, i.e.
you can have the server load a PHP script that produces CSS like so:
Note that this will only work if the scripts emits a text/css header:
Now your PHP script can define some constants that you simply insert into your CSS:
Your script could also load various CSS files for processing and output the result in one go, solving the second problem we found. But we can do better still. You can have your PHP script use Smarty to produce the CSS, making the use of contants easier (and prettier):
style.css would be the main style sheet manifold; it could load other (sub-) stylesheets. For instance:
The values that were assigned to
inputcolor can be used in the sub-stylesheets like so: