Table Tutor - Lesson 4 |
Let's get rid of CELLPADDING and CELLSPACING and go back to our simple little table.
<TABLE BORDER=3> <TR> <TD>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
A cool feature of the newer browsers is the ability to specify background colors for a table cell, row or the whole table. You use BGCOLOR just like you would in the <BODY> tag.
<TABLE BORDER=3 BGCOLOR="#FFCC66"> <TR> <TD>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
<TABLE BORDER=3> <TR BGCOLOR="#FF9999"> <TD>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR BGCOLOR="#99CCCC"> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
<TABLE BORDER=3> <TR BGCOLOR="#FFCCFF"> <TD>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD BGCOLOR="#FF0000">Larry</TD> <TD>Curly</TD> <TD BGCOLOR="#3366FF">Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
Here's a handy chart I use to choose background colors. There are also 2 charts in HTML format, one with 216 colors and another with 1536 colors. You can also use Color Picker for playing around with colors.
One more thing about these table background colors... a <TD> bgcolor will override a <TR> bgcolor and a <TR> bgcolor will override a <TABLE> bgcolor. Not that this needs further explanation but I'm kind of having fun with this so here's an example:
<TABLE BORDER=3 BGCOLOR="#FF6633"> <TR BGCOLOR="#009900"> <TD BGCOLOR="#9999FF">Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
Let me take a minute to esplain something. A browser has to interpret the instructions you give it the best way it can. If something has not been specified one way or another, most browsers will try to come up with an attractive solution. The best thing you can do as an author is to specify as much as you can, especially those things that are important for your page to look right. It is also important to view your work through those browsers that people actually use. Since most people use Netscape or Internet Explorer, that is a good start. You may also want to have a copy of a couple other less popular browsers to be sure that you look right to them too.
Another consideration is screen resolution. I work on a 640x480 screen. Many people use 800x600 and many have theirs set to 1024x768 or even 1600x1200. This simple difference has the potential to seriously mess with your page design. There is a little Win95 utility that I use called QuickRes that can change your screen resolution back and forth with the click of a button. It's not a bad idea to view your pages through other resolutions.
Now we will play with COLSPAN (Column Span) and ROWSPAN (Row Span maybe??). Let's suppose Ed beats the crap out of Tom and throws him out of the table. Just doing that, this is what we have.
<TABLE BORDER=3> <TR> <TD>Ed</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Rick | |
Larry | Curly | Moe |
It just left an empty spot and Rick slid over to fill the void.
<TABLE BORDER=3> <TR> <TD COLSPAN=2>Ed</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Rick | |
Larry | Curly | Moe |
To emphasize the point I made earlier, about the browser trying to find an attractive solution, let's make Ed span two columns but we'll put Tom back in. We will deliberately introduce a discrepancy just to see how the browser handles it.
<TABLE BORDER=3> <TR> <TD COLSPAN=2>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick | |
Larry | Curly | Moe |
The point is 1) The browser is very forgiving in that it does the best it can with what you give it. 2) It is very important to specify what is important and make sure there are no discrepancies or you may end up with a surprise. And 3) there's very little you do with html will crash the other person's browser no matter how badly you may have messed it up, so don't worry about that.
OK... let's take Tom back out (the poor sap).
<TABLE BORDER=3> <TR> <TD COLSPAN=2>Ed</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Rick | |
Larry | Curly | Moe |
Rick gets scared and he leaves. Ed takes over Rick's cell too, and just cause he's that way, he stands right in the middle of the cell.
<TABLE BORDER=3> <TR> <TD COLSPAN=3 ALIGN="center">Ed</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | ||
Larry | Curly | Moe |
All other html coding, by the way, can be used in a cell. We'll make Ed bold as an example.
<TABLE BORDER=3> <TR> <TD COLSPAN=3 ALIGN="center"><B>Ed</B></TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | ||
Larry | Curly | Moe |
We'll make him a link to my homepage.
<TABLE BORDER=3> <TR> <TD COLSPAN=3 ALIGN="center"><A HREF="http://junior.apk.net/~jbarta/">Ed</A></TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | ||
Larry | Curly | Moe |
Now get rid of all that stuff, bring back Tom and Rick and we'll dive into <ROWSPAN>.
<TABLE BORDER=3> <TR> <TD>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Larry</TD> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Larry | Curly | Moe |
As you may have guessed, <ROWSPAN> is just like <COLSPAN> 'cept y'all span rows instead of columns. (Not exactly brain surgery... is it?)
If we remove Larry and let Ed take over his cell, this is the result.
<TABLE BORDER=3> <TR> <TD ROWSPAN=2>Ed</TD> <TD>Tom</TD> <TD>Rick</TD> </TR> <TR> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | Rick |
Curly | Moe |
And of course, these attributes can also be used in combination.
<TABLE BORDER=3> <TR> <TD ROWSPAN=2>Ed</TD> <TD COLSPAN=2>Tom</TD> </TR> <TR> <TD>Curly</TD> <TD>Moe</TD> </TR> </TABLE>
Ed | Tom | |
Curly | Moe |
|