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:
<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>
famous last words | |
---|---|
eenie | meenie |
miney | moe |
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:
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.