Maddog's HTML for Real People Chapter 10, Lesson 10


[INDEX] Ch 10, L 10 - Background Color for Data Cells

If you already know how to specify the background color for an individual data-cell, you can skip this lesson.

Some advanced browsers (Netscape and Internet Explorer, for example) allow the background color to be specified for individual cells. While all browsers may not support this, we'll let you know about it anyway.

You can specify the BackGround COLOR for a table-data or table-heading cell (apart from that specified for the HTML 'body' or 'table'). To do this, use the 'BGCOLOR' attribute in the cell's opening tag, as follows:

<TD BGCOLOR="#RGB-code">
or
<TD BGCOLOR="color-name">
or
<TH BGCOLOR="#RGB-code">
or
<TH BGCOLOR="color-name">

Let's see this demonstrated:

HTML Source Code Follows:

<TABLE  BORDER=5 WIDTH=40%>
<TR>
    <TH BGCOLOR="YELLOW" COLSPAN=2>famous last words</TH></TR>
<TR ALIGN="CENTER">
    <TD BGCOLOR="LIME">eenie</TD>
    <TD BGCOLOR="LIME">meenie</TD></TR>
<TR ALIGN="CENTER">
    <TD BGCOLOR="FUSCHIA">miney</TD>
    <TD BGCOLOR="FUSCHIA">moe</TD></TR>
</TABLE>
(End of HTML Source Code)

Demonstration Follows:

famous last words
eenie meenie
miney moe

(Demonstration Ends)

As you can see from the demo (if your browser supports background colors in individual cells), we've specified a different color for the heading cell, and each row. To specify the color in each row, we specified the color in each data cell in that row (rather than for the row itself).

By specifying the background color for each cell, we avoided having to "nest" tables to get cells with individual colors (which is what we did with the last lesson). Keep in mind this heirarchy, however:

  1. not all browsers that might load your web page will support tables;
  2. not all browsers that support tables support background color for tables;
  3. not all browsers that support background color for tables support background color for individual cells
I suspect (but I can't show figures to support it) that the potential audience lost because you use tables is between 20-30% of the total web population, and that of the remainder (that do support tables) 20-30% of that audience will not support either nested tables or background colors in tables, but that of the remainder (that do support background color in tables) 20-30% of that audience will not support background color in individual cells. As we shall see in the following chapter, when using tables to build fancy, borderless graphic web pages, it's important to consider these issues. One obvious consideration, for example, is how the table will look if the default background color (usually white or light-gray) is applied instead of colors you specified.

As HTML evolves, and folks update their browser software, the percentages of audience lost will progressively decrease, though (I suspect) there will always be 5-10% of the internet population continuing to use less-featured browsers.


-PREVIOUS- -CHAPTER- -INDEX- -NEXT-

Overseer: Monty Northrup ... maddog@io.com ... leave e-mail ...
...to maddog 'n' miracles homepage...