Variables in CSS ???

liunx

Guest
I am not sure if this can be done or not, but I thought I would put it out there just to find out...

Is it possible to assign variables in css, and then use the values later? For example, if I am using 3 colors on my site, would I be able to do something such as


color1 = #FF0000;
color2 = #0000FF;
color3 = #000000;


somewhere in my style sheet and then later use these variables in my styles?


.myClass {
color: ${color1};
background-color: ${color2};
}


Just wanted to know if there was a way that I could change colors throughout the whole stylesheet by only changing it in one place, instead of having to do a find/replace.I do not think that using variables within the CSS rules will work without the use of JavascriptTrue, it might work with javascript and if does work then I dont think it's W3C compliant!http://www.webdeveloper.com/forum/showthread.php?s=&threadid=36424As nifty as what Vlads linked to is, I have a PHP solution that I use that might help you out. I just create a function, with RegEx to indent CSS from the way I write it to human readable, as well as convert, say [==HEADER==] to url(header/summer2.jpg). This is accomplished with output buffering and its user defined function, that function being the one that indents and replaces. And if all you want to do is replace phrases, then its all the more easier. (Of course, the entire thing is a PHP file, header() changes the content type to CSS.

Pretty common, but apparently so was Faux columns, and I never thought of that...
 
Back
Top