Forum Moderators: not2easy

Message Too Old, No Replies

Defining an alias for a color?

         

willamowius

1:44 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



In my stylesheets I usually have 2 or 3 colors that are used in lots of definitions.
I would like to keep those colors easily changable.

Instead of writing

h1 { color:#123456; ... }
hr { color:#123456; ... }

I'd like to use somthing like

DEFINE PRIMARY-COLOR #123456
h1 { color:PRIMARY-COLOR; ... }
hr { color:PRIMARY-COLOR; ... }

Is something like that available?
How do you manage such recurring patterns?

moltar

2:26 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is not available. It is pain in the a**, but what you gonna do... I manage it the same way you do :) Search and replace helps a lot though.

encyclo

3:38 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can of course simply list the elements which need the specific color:

h1, h2, h4, p, div#whatever, .widgets, hr {
color:#123456;
}

CSS doesn't work like a programming language, so you have to look for other ways to better organize the styles.

sonjay

4:17 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



Hmmmm.... I wonder if you tell your server (in .htaccess) to parse .css files for php, if you could then use php in the file to write out the css file based the variables.

Has anyone tried this? I might try it later on if I have some time, to see if it would work. It would make life so much easier.

encyclo

4:31 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sonjay, there's a thread about using server-side scripting in a CSS file around here somewhere... Ah, here it is [webmasterworld.com]!

Basically, you can link to a PHP/ASP file, but make sure that you send the appropriate mime-type as a header (text/css), and above all, make sure you fully test what is happening with the caching of the resulting file, and add headers for Last-Modified etc. as required.