RE: How to define a CSS constant

> I want to create a constant in my CSS file so that I can change
> all affected
> properties in one place. For example, in order to provide alternative
> schemes one might assign a constants "myfontsize", "myfontcolor".
> I thought
> I'd seen something like @define somewhere but can't find anything about it
> now. Can this be done and if so how please?

A friend of mine has a word for questions like this. That word is probably
best transcribed as "g'neh!" (I'll be curious to find out what
screen-readers make of that :) It roughly translates to "I know an answer to
that question, but I'm not sure it would be wise for you to use it."

In general such a @define rule would be a bad thing. I can however see a
case for something like that where the CSS is meant to respond to
instructions from someone other than the person who coded it (in particular,
instructions from someone who doesn't know how to code CSS).

In such cases you can use something like ASP or similar to create the CSS
on-the-fly, and get most of the benefits of the @define:

paragraph {
	color: <%=colour_const_or_function%>;
}

That said in a well-written CSS there should be relatively little
duplication of values (as David points out), so if you are only using
constants here it may be wise to re-examine the CSS entirely.

If you do use an on-the-fly solution remember to use Last-Modified and cache
control so you don't have to generate it for every use.

Received on Thursday, 14 November 2002 08:23:18 UTC