CSS Testiness

OK, I’m a huge fan of CSS. To paraphrase the Amex commercial, “I don’t build a Web site without it.”

Yet I have complained (from time to time) about shortcomings in CSS, real or perceived.

One complaint I’ve been voicing (under my breath, to myself) recently is the lack of variable scope in CSS.

There aren’t any varibles (much less additional scope) in a CSS file, unless you parse out a NON “.css” file (myCSS.php) and make replacements in this way.

This works, but then it is not as flexible.

Yes yes yeah yeah….CSS is spozed to be this static include file blah blah.

But just as the Web — with it’s static HTML pages — evolved to a very dynamic code-generation system (“No database? That is so 1996..”), one would think that this logic would be available for CSS. Doesn’t appear that it is. CSS is killing me.

Personalization and ease of maintenance calls for CSS to be more dynamic.

Is this possible – in a regular CSS file???

I don’t know of it, but I’d like it.

Take a simple example, for one area of a site without personalization: The same colors echo – either as “color” or “background-color” throughout the style sheet. If I want to change the background color from black (with white text) to white (with black text) I have to do all sorts of switches, including those for hovers, links and so on.

Isn’t there are programatic way — within the style sheet — to make these variables (“$dark = #000000; $lite = “#ffffff”)….well, variables?

Yes, I can do it through scripting, or “search and replace” …but…why?

Why can’t I change three variables in a “.css” file and have that cascade?

Interesting thought. I’ve done a bit of work with this, with personalization (either from a database or cookie) and applied these user preferences to a NON-css file (a file that can be parsed so the variables I pass to it are captured) that is then written out as a

write.

I’ve also done it so each user – upon selection of either schema or personalized choices – gets a “unique” style sheet that is then written out and included each time (this seems more efficient; also more clumsy – if cookie or db values, why not just include them into an included file? Want 12,000 “[user_id].css” files clogging up your file system??)

I have to get deeper into this…

04/16/2003 update: Yes, I know you can use JavaScript to make the changes (I do this on the “Text size” link in the menu), but — again — this is programatic, not variable-based. Still have to, for example, change every instance of “#000000” to “#ffffff” or whatever. Not just saying “$darkColor = #ffffff” and having it apply globally.