View Full Version : Linking Color In CSS

05-11-2009, 03:59 AM
I have a standard CSS file that I simply edit for the next site I'm building. I'm trying to figure a way to link an individual color to multiple selectors in the CSS.

For example, let's say I have 3 primary colors I'm using and they are being shared between fonts, backgrounds, tables, etc. Thus there could be 30 different places calling out the color code in one style sheet. If for some reason I need to adjust the colors, I must edit every line in the CSS with that color code (30 times).

I'd like to setup the three colors in their own selectors. Then reference the fonts, backgrounds, and tables to those colors. All in the CSS. This way I can easily adjust the three color syntaxes and have all the pages update.

Any thoughts on this?

(And I do realize I can do a find/replace all to change the color codes.)

05-11-2009, 04:12 AM
make a class . check the different links in my sig might help you

05-11-2009, 04:42 AM
Thanks Concord, however in your example you are using a couple of different color codes, #000, #fff, #FF0000 and so forth. You wound up inputting these hex codes a couple of times per color.

I guess in an essence, I'm trying to create a class for the three colors. Then want to apply those classes to different divs and elements, however all in the style sheet, or a couple style sheets. I just want to edit one iteration of the hex code and have it change all the syntax.

05-11-2009, 05:16 AM
it was meant as a guide add atributes for any class or div you want
each so a div could have its own styling or for ie you could use <p class="your_class">

d a v e
05-11-2009, 01:06 PM
simply use a css editor with find and replace then you only have to type
replace #xxx with #yyy ;)

05-11-2009, 04:25 PM
you can define a styles for multiple selectors by separating them with a comma:

h1, h2, p, #id, .class, .etc, .etc {color: #ff0;}

05-11-2009, 04:27 PM
you can also use php variables in a style sheet: http://www.studiojmc.com/design-blog/css-variables.html but to be honest, I haven't found it to be worth the trouble.

05-16-2009, 09:38 AM
mmmm... I didn't think of the multiple selectors to one style. I'll give that a try.