Contact Us

Control Your CSS Via PHP - Good Stuff!

Posted on 23/5/07 by Tim Koschützki

Today I stumbled upon a cool article that explains how one can control one's CSS colors via PHP to form relative shades. How is this done I hear you asking? Just look at the following code:

$base = new CSS_Color('C9E3A6');
$highlight = new CSS_Color('746B8E');
/* Use the base color, two shades darker */
background:#< ?= $base->bg['-2'] ?>;

/* Use the corresponding foreground color */
color:#< ?= $base->fg['-2'] ?>;

/* Use the highlight color as a border */

Note that we generate a CSS color object and then form lighter or darker shades of it using relativities. That could make generating cool design very easy. Just change the base color and with the relativities the entire design should change accordingly and still be eye-candy. Cool stuff isn't it? :)


You can skip to the end and add a comment.

[...] the website today, there’s a new post that, using a tip from this article on BarelyFitz, shows how to control CSS information with PHP. [...]

Nate Klaiber said on May 24, 2007:

I think this is a very simple way to generate schemes and such - very handy tool.

However, i think it might be some overhead to generate this for every page request - so I would mix this with a cached file of your layout/colors (they don't need to be changed dynamically with each request, do they?).

Tim Koschuetzki said on May 25, 2007:

Yes you are absolutely right. One should only use this to generate the css script and then go with it. Whenever you want to change it, you call the php tool again and then copy & paste it to your css file again.

[...] Articles Control Your CSS Via PHP - Good Stuff!Parsing XML using SimpleXMLPHP Code-Beautifier ToolKeystroke Counter ToolPrinciples in [...]

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.