Let's set the table... |
|
|||||||||||||||||
...and completely revolutionize ordinary web pages |
Tables were introduced into HTML 3.0 and further enhanced by Netscape to add another dimension to web page design. They provide a structure for organizing other HTML elements into "grids" on the page. One of the more obvious uses of tables is when you have to format... columnar tables of text! But, tables also open up the door for many other page layout options.
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, them 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
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> |
|
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.
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> |
|
There is still quite a bit more to cover, but let's stop looking at these boring examples and work on our web page...
<table border> <tr> <th>Eruption</th> <th>Date</th> <th>Volume in km<sup>3</sup></th> </tr> <tr> <td>Paricutin, Mexico</td> <td align=center>1943</td> <td align=center>1.3</td> </tr> <tr> <td>Mt. Vesuvius, Italy</td> <td align=center>79 A.D.</td> <td align=center>3</td> </tr> <tr> <td>Mount St. Helens,<br>Washington</td> <td align=center>1980</td> <td align=center>4</td> </tr> <tr> <td>Krakatoa, Indonesia</td> <td align=center>1883</td> <td align=center>18</td> </tr> <tr> <td>Long Valley, California</td> <td align=center>pre-historic</td> <td align=center>>450 & <700</td> </tr> <tr> <td>Yellowstone, Wyoming</td> <td align=center>pre-historic</td> <td align=center>400</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)
NOTE: The table may not be completely distinct as it sits on a solid black background.
<table border=X cellpadding=Y cellspacing=Z>where X is the width (in pixels) of the outer border of the table. The attribute cellpadding specifies how much empty "space" exists between items in the cells and the walls of the cells -- high values for Y will make the cells larger ("padding" the cell). The attribute cellspacing specifies (in pixels) the width the inner lines that divide the cells.
Modify your <table> tag to read:
<table border=3 cellpadding=4 cellspacing=8>
<table border=3 cellpadding=4 cellspacing=8> <caption><b><font size=+1> Volumes of Some Well-Known Volcanic Eruptions</font></b></caption>You can include and HTML inside the <caption> tag; just makes sure that it is within the <table>...</table> tags.
<tr> <th><font color=#EE8844>Eruption</font></th> <th><font color=#EE8844>Date</font></th> <th><font color=#EE8844>Volume in km<sup>3</sup></font></th> </tr>
<tr> <th></th> <th><font color=#EE8844>Eruption</font></th> <th><font color=#EE8844>Date</font></th> <th><font color=#EE8844>Volume in km<sup>3</sup></font></th> </tr>
<tr> <td rowspan=4> <font color=#EE8844> <i>eruptions<br> observed<br> by humans</i> </font></td> <td>Paricutin, Mexico</td> <td align=center>1943</td> <td align=center>1.3</td> </tr>
NOTE: We have added some <br> tags so that this first column does not become too wide. You might want to investigate for yourselves the effect of omitting these tags.
<tr> <td rowspan=2> <font color=#EE8844> <i>inferred<br> by study<br> of deposits</i> </font></td> <td>Long Valley, California</td> <td align=center>pre-historic</td> <td align=center>>450 & <700</td> </tr>
A Phantom table is built in the same manner as the table we built above except the <table> tag looks like:
<table>or
<table border=0>On some browsers, just omitting the border attribute will cause it to display a table without any lines marking the cells. On other browsers, you will have to set the border to 0 pixels for the same effect.
If you look at the very top of this page, the top most part is actually a Phantom table that contains in one of its cells a second table with borders! However, we are jumping ahead. For our example, we will reformat the file usa.html (Volcanoes in the USA) into a two column format. Rather than having page-wide paragraphs stacked vertically on the page, we will put them side by side like this sketch:
XXXXX [title] |
XXXXX
[title] |
||
xxxxx xxxxx xxxx xxx xx xxxxx xx xx xxxx xxxxx xxxxx |
xxx xx x xxxx xxx xx x x xx xx xxxx xxxxx xx x xxxxx xxx xxxxx |
_______ | img | | | |_____| |
[image link to big image] |
xxx xx xx [hypertext link to big image] |
Note that the right hand column also has an adjacent picture that is a hyperlink to a full screen image (see lesson 8e)
<font size=+1><B>Mount St Helens</B></font><br> On May 18, 1980, after a long period of rest, this quiet mountain in Washington provided <a href="msh.html">detailed observations</a> on the mechanics of highly explosive eruptions. <p> <font size=+1><B>Long Valley</B></font><br> This field seismometer measures earthquakes associated with subsurface volcanic forces and may help to predict future events. It sits on a plateau known as the "Volcanic Tableland" formed by a major eruption 600,000 years ago.<p> <a href="../pictures/seismo.jpg"> <img src="../pictures/stamp.gif"> -- [full size image] --</a>and replace it with the following HTML:
<table cellpadding=6> <tr> <td><font size=+1><B>Mount St Helens</B></font></td> <td colspan=2><font size=+1><B>Long Valley</B></font></td> </tr> <tr> <td valign=top>On May 18, 1980, after a long period of rest, this quiet mountain in Washington provided <a href="msh.html"> detailed observations</a> on the mechanics of highly explosive eruptions. </td> <td valign=top> This field seismometer measures earthquakes associated with subsurface volcanic forces and may help to predict future events. It sits on a plateau known as the "Volcanic Tableland" formed by a major eruption 600,000 years ago. </td> <td valign=top><a href="../pictures/seismo.jpg"> <img src="../pictures/stamp.gif"></a> </td> </tr> <tr> <td colspan=3 align=right> <a href="../pictures/seismo.jpg"> -- [full size image] --</td> </tr> </table>
NOTE: Look carefully at the HTML here. We actually are using a 3 column table -- the first paragraph (Mount St Helens) becomes the left column. The right column includes one column of text and another column for a small image. A bottom row, aligned right and spanning 3 columns, is used to hold the hypertext link that leads to the same graphic as the thumbnail image
The effect is to transform a list:
Long Linear List | Column 1 | Column 2 | |
---|---|---|---|
<ul> <li> xxxxxx <li> xxxx xxxx <li> xxx x xxxx <li> xxx xxxxx <li> xx x xxxxx <li> xxx xx <li> xxxx x <li> xxx x xxx </ul> |
to |
<ul> <li> xxxxxx <li> xxxx xxxx <li> xxx x xxxx <li> xxx xxxxx </ul> |
<ul> <li> xxx xx <li> xxxx x <li> xxx x xxx </ul> |
We will now break up the list of resources on our Resource Projects page (file proj.html).
<table> <tr> <td valign=top> <ul> <li><A HREF="http://www.avo.alaska.edu/"> Alaska Volcano Observatory</A> <li><A HREF="http://vulcan.wr.usgs.gov/home.html"> Cascades Volcano Observatory</A> <li><A HREF="http://www.dartmouth.edu/~volcano/"> The Electronic Volcano</A> <li><A HREF="http://www.geo.mtu.edu/volcanoes/"> Michigan Tech Volcanoes Page</a> <li><A HREF="http://www.geo.mtu.edu/eos/"> NASA Earth Observing System (EOS) IDS Volcanology Team</A> <li><A HREF="http://www.geol.ucsb.edu/~fisher/"> Volcano Information Center</a> </ul> </td> <td valign=top> <ul> <li><A HREF="http://vulcan.wr.usgs.gov/Servers/earth_servers.html"> Volcano/Earth Science-Oriented Servers</A> <li><A HREF="http://www.ngdc.noaa.gov/seg/hazard/hazards.html"> NGDC Natural Hazards Data</a> <li><a href="http://www.nmnh.si.edu/gvp/"> Global Volcanism Program (GVP) </a> <li><a href= "http://www.soest.hawaii.edu/hvo"> Volcano Watch Newsletter</a> <li><a href="http://www.jasonproject.org/JASON/HTML/EXPEDITIONS_JASON_6_home.html"> JASON Project VI: Island Earth</a> <li><A HREF="http://volcano.und.nodak.edu/"> VolcanoWorld</A> </ul> </td> </tr> </table>
NOTE: We simply have taken one <ul>...</ul> list and broke it into two complete lists, each in the cell of an invisible table with one row and two columns.
You might want to look at the last example on the test page to see if your browser supports coloring of tables.
We will uses the hex color codes that we used in lesson 16 to color the background of web pages and in lesson 18 to color text.
It is as simple as inserting bgcolor=#FF0000 as an attribute to the different <table> tags:
Table Part | HTML |
---|---|
table color the area behind the entire table |
<table bgcolor=#880000> |
row color the area behind a single row |
<tr bgcolor=#880000> |
cell color the area behind a single cell |
<td bgcolor=#880000> |
Now we will add some color to the data table you created for the Introduction page. We will not add great gobs of colors (but feel free to experiment on your own pages). In our case, we will simply add the HTML to make the cells that hold the row and column headings a lighter shade of gray than the background black.
<th><font color=#EE8844>Eruption</font></th> <th><font color=#EE8844>Date</font></th> <th><font color=#EE8844>Volume in km<sup>3</sup></font></th>and add the attribute to color those cells grey (#222222):
<th bgcolor=#222222><font color=#EE8844>Eruption</font></th> <th bgcolor=#222222><font color=#EE8844>Date</font></th> <th bgcolor=#222222><font color=#EE8844>Volume in km<sup>3</sup></font></th>
<td bgcolor=#222222 rowspan=4> <font color=#EE8844> <i>eruptions<br> observed<br> by humans</i> </font></td> : : : <td bgcolor=#222222 rowspan=2> <font color=#EE8844> <i>inferred<br> by study<br> of deposits</i> </font></td>
The Internet Connection at MCLI is
Alan Levine --}
Comments to levine@maricopa.edu
URL: http://www.mcli.dist.maricopa.edu/tut/tut21.html