Let's set the table... |
|
||||||||||||
...and completely revolutionize ordinary web pages |
The HTML for tables can look very complex -- but we will start simple and build up some tables for our Volcano Web lesson.
For starters, keep in mind this concept:
Tables start being built from the top left, then across the columns of the first row, then to the second row, across the columns of the second row...--> --> --> --> --> --> ___________________________| | --> --> --> --> -->We will call each grid in a table a cell.
The HTML for the basic table structure is shown below:
HTML | Result | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
<table border=1> <tr> <td>Row 1 col 1</td> <td>Row 1 col 2</td> <td>Row 1 col 3</td> </tr> <tr> <td>Row 2 col 1</td> <td>Row 2 col 2</td> <td>Row 2 col 3</td> </tr> <tr> <td>Row 3 col 1</td> <td>Row 3 col 2</td> <td>Row 3 col 3</td> </tr> </table> |
|
The border=1 attribute in the <table> tag instructs the browser to draw a line around the table with a thickness of 1 pixel. Note how each row is defined by Table Row tags <tr>...</tr> and then cells in each row are defined by Table Data <td>...</td> tags. Each <td>...</td> tag can contain any type of HTML tag we have used in this tutorial -- headers, styled text, hypertext links, inline graphics, etc. Within this tag you can uses several attributes to control the alignment of items in a single cell:
Horizontal Alignment | Vertical Alignment |
---|---|
|
|
You can combine these attributes:
<td align=left valign=bottom>
This HTML will produce a cell with items aligned along the left and bottom of the cell.
The table shown above is pretty simple and square -- three rows by three columns. Look what we can do if using the colspan and rowspan attributes in the <td>...</td> tags.
HTML | Result | ||||||||
---|---|---|---|---|---|---|---|---|---|
<table border> <tr> <td>Row 1 col 1</td> <td align=center colspan=2> Row 1 col 2-3</td> </tr> <tr> <td>Row 2 col 1</td> <td>Row 2 col 2</td> <td>Row 2 col 3</td> </tr> <tr> <td>Row 3 col 1</td> <td>Row 3 col 2</td> <td>Row 3 col 3</td> </tr> </table> |
** Note the attribute for the second cell of the first row -- it spans 2 columns. We have also aligned the text in the center of this cell. |
||||||||
|
|||||||||
Okay, now that we have had a cell span two columns -- let's make a cell that spans two rows. Remember to follow the HTML as it builds from the top left across, then down, then across... | |||||||||
HTML | Result | ||||||||
<table border=1> <tr> <td>Row 1 col 1</td> <td align=center colspan=2> Row 1 col 2-3</td> </tr> <tr> <td>Row 2 col 1</td> <td valign=top rowspan=2> Row 2 col 2</td> <td>Row 2 col 3</td> </tr> <tr> <td>Row 3 col 1</td> <td>Row 3 col 3</td> </tr> </table> |
|
NOTE: Look at the HTML for the first row. The Table Header tags <th>...</th> function exactly like the <td>...</td> tags except that any text is automatically made bold and all items are automatically centered.
Also see that in the cells for "Long Valley" you must use the HTML for the special characters to display the symbols for "<", ">", and "&" (See lesson 10)