Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use CSS to define colors on table? 1

Status
Not open for further replies.

Ram0135

Technical User
Apr 14, 2003
77
US
Hello,
I have a site in which I want to use 2 different CSS sheets to define color schemes. Currently I have a couple of tables with their background colors defined. I want to know if I can set the color value to a value which is pulled from the CSS file. So when someone clicks on a link to switch the CSS to the 2nd one, it will change the color scheme as well. Here is what I currently have:

Code:
<td width="181" height="36" bgcolor="#FF6600"><div align="center" class="style3">SAMPLE TEXT</div></td>

I want the value #FF6600 to be a dynamic value which is loaded from the corresponding CSS sheet. Like COLOR 1 and the CSS would reference COLOR 1 to a color value. I am on an ASP server as well. I also possibly want to set cookies to remember the values but that's easy to do.

Thanks,
Ram0135
 
It's simple - use an ASP variable to load seperate css files.
Code:
<link rel="stylesheet" type="text/css" href="[COLOR=blue]<% $css %>[/color]" />

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Simpler than that, give your cells a [tt]class[/tt] and apply the choice of colour in your style sheet. So your cells could be like this (I'm removing the apparently unnecessary <div> too):
Code:
<td width="181" height="36" class="sample">SAMPLE TEXT</td>
and your CSS would be like this
Code:
.sample {
   text-align: center;
   background: #FF6600;
}
You should also try to make full use of CSS's ability to select elements based on their context. So if you wanted to have some (but not all) tables on your site to have red headings and green data cells, you wouldn't have to apply a class to every cell. Just class the table
Code:
<table class="eyestrain">
and use the power of CSS
Code:
table.eyestrain th { color: red; }
table.eyestrain td { color: green; }

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thank you both for your insight. I tried Chris's idea and it worked as I wanted it too! Thanks Chris!

Ram0135
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top