CSS, Inheriting Colors

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
supermike
Forum Contributor
Posts: 193
Joined: Tue Feb 28, 2006 8:30 pm
Location: Somewhere in the Desert, USA

CSS, Inheriting Colors

Post by supermike »

Is there a way that I can have multiple classes in my CSS that inherit colors from another class or one central source? That way, I can just change the color scheme at the top and it replicates down.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Not exactly sure what you mean. Is the normal inheriting not enough?

Or maybe you want some kind of groups of styles?

Code: Select all

html:

<body class="bluestyle">
<div id="content">
..
</div>
</body>

or

<body class="redstyle">
<div id="content">
..
</div>
</body>


css:
body.bluestyle {
  color:#256;
}
.bluestyle #content {
  color:#258;
}
.bluestyle #content #intro {
  color:#235;
}

body.redstyle {
  color:#500;
}
.redstyle #content {
  color:#700;
}
.redstyle #content #intro {
  color:#900;
}
This way, you'll only have to change one class in the html for a complete styleswitch.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

When it comes to styling a page I usually write two stylesheets. One houses the colors of certain elements (body, h1, p, pre, etc...) and the others handle positioning and layout. Then, I can actually create several color variants of the same page and use them interchangeably depending on what I want to see.

You can call two stylesheets in the same manner that you call one.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Alternatively, you could write a PHP file that mimics a CSS file. That way you could store colours in a PHP variable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That's even sweeter. :)
Post Reply