Help - Search - Members - Calendar
Full Version: Is there a way to change the background color on tables?
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
Aruban
I want to be able to change the background color of specific cells in a table as opposed to changing every cell in the table. Is there a way to do this?

Thanks.
pandy
Sure, with the bgcolor attribute.
http://www.htmlhelp.com/reference/html40/tables/td.html
It's better done with CSS though.
http://www.htmlhelp.com/reference/css/colo...ound-color.html
Aruban
Sorry. I asked the wrong question. What I meant to ask was:

Is there a way to change a cell's background color based upon the variable within that cell?

Thanks.


QUOTE(pandy @ Nov 2 2006, 06:08 PM) *

pandy
Variable? blink.gif
Aruban
I have a form users are filling out. When completed and submit button is pressed, all the information is reprocessed onto a handling page....it's reformatted using tables. I want certain cells in the tables to change background colors based upon the users input in that category.


QUOTE(pandy @ Nov 2 2006, 06:15 PM) *

Variable? blink.gif

Darin McGrew
The cleanest way is to use CSS classes, and to have the server-side program that is processing the form data to assign classes based on the input. Something like

if (value == "apple") then print "<td class='redfruit'>"
if (value == "orange") then print "<td class='orangefruit'>"
if (value == "banana" || value == "lemon") then print "<td class='yellowfruit'>"
...
Aruban
Thanks Darin. The other thing I noticed as I was experimenting with background colors in tables is that, if I print the html file, the colors don't show up. It's all black and white. I double-checked my print settings, which are set for color. Any thoughts?


QUOTE(Darin McGrew @ Nov 2 2006, 06:24 PM) *

The cleanest way is to use CSS classes, and to have the server-side program that is processing the form data to assign classes based on the input. Something like

if (value == "apple") then print "<td class='redfruit'>"
if (value == "orange") then print "<td class='orangefruit'>"
if (value == "banana" || value == "lemon") then print "<td class='yellowfruit'>"
...

Darin McGrew
QUOTE(Aruban @ Nov 2 2006, 03:27 PM) *
The other thing I noticed as I was experimenting with background colors in tables is that, if I print the html file, the colors don't show up. It's all black and white. I double-checked my print settings, which are set for color. Any thoughts?
I've seen this kind of thing when the style sheet is specified for media="screen" rather than media="screen,print". The article Going to Print discusses print style sheets as a positive thing, but the flip side is that if you specify style sheets for screen only, then they won't apply when the page is printed.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.