Back Home  > Projects > Creating Web Tables

Creating Web Tables
Dr. Linda M. Perry

You've probably noticed by now that the web pages in these exercises have been very simple and linear; that is, the elements on the page are stacked vertically. To control placement of elements on the page, you must use tables. Even if you use Web-authoring software to design your Web pages, it's still helpful to know and understand HTML coding for tables so you can make adjustments to a page. Sometimes it's easier to add or edit tables via coding than it is on the WYSIWYG design view.

Let's take the page you created on the Preparing Web Graphics exercise and add some tables and text so that the page looks like this one.

To do that, open the text file you created in HTML coding. It should look something like this:

<html>
<head>
<title>Graphics on the Web</title>
<body text="#000000" link="#993333" vlink="#993333" alink="#330000" bgcolor="#fffffff" >
<h2 align="center">The Baughman Center</h2>
<p>The University of Florida <a href="baughman.html">Baughman Center</a> is located on the west bank of Lake Alice.</p>
<a href="baughman.html"><img src="thumbbaughman.gif" width=60 height=60 border=1 alt="The Baughman Center"></a>
</body>
</html>

 Place your cursor after the words: "located on the west bank of Lake Alice." Right before the closing </p> code, add this text:

The thumbnail photo of the Baughman Center, at left, is a link to a view of the center from Lake Alice's observation deck near Cory Village.

Now look at your page in a browser. You'll notice that the text stretches all the way across the browser and extends in length when the browser window is stretched. We want to control both the size of the Web page (designing for 800 by 600) and the placement of elements. (Be sure to read About Using Tables in Chapter 13 of Williams' Non-Designer's Web Book.)

Your Barebones Guide to HTML will give more details about tables, but we are going to use just three basic table elements:


one for the table <table>----->


.


one for the row(s) <tr>-------->
Every table needs at least a row command, which always precedes the cell command.


.

.


and one for the cells. <td>--->


..

..

.

.

.

First let's enclose the whole web page in a table to control the width of the page. After the body tag with all its attributes (link colors, background color, etc.), add the table code and specify its width, and set its alignment, like this:

<table width=750 align="center">

(750 accommodates the space taken up by the browser window). We won't control the height, but we could. The default border is 0 pixels, so the table is invisible. After the table code, type the row and cell command. It all should look like this:

<table width=750 align="center"><tr><td>

Put the closing-off code at the end of the document, right before the closing </body> code. It must be in exact reverse order. It looks like this:

</td></tr></table>

Your entire page of coding should look like this (new elements here are in bold, but yours won't be):

<html>
<head>
<title>Graphics on the Web</title>
<body text="#000000" link="#993333" vlink="#993333" alink="#330000" bgcolor="#fffffff" >
<table width=750 align="center"><tr><td>
<h2 align="center">The Baughman Center</h2>
<p>The University of Florida <a href="baughman3.html">Baughman Center</a> is located on the west bank of Lake Alice. The thumbnail photo of the Baughman Center, at right, is a link to a view of the center from Lake Alice's observation deck near Cory Village.</p>
<a href="baughman3.html"><img src="thumbbaughman3.gif" width=60 height=60 border=1 alt="The Baughman Center"></a>
</td></tr></table>
</body>
</html>

Now view your html page in a browser. It should snap to a width of no more than 750 pixels, no matter how large the browser is stretched, and be centered in the browser. (You can also align left and right.) But the layout is still linear. To control placement of elements, we must nest a table inside the large table we created.

TOP ........ Controlling Placement

We want a nested table with one row and two columns, or cells, so we can put the text beside the picture and control its placement. We'll start with the table and row codes, immediately after the Baughman Center heading, then place the cell codes to "capture" the graphic and the text and put them where we want them. We'll use the vertical alignment code (valign) to place the text at the top of the cell. It could also be vertically aligned at the middle or bottom of the cell. If you don't give a vertical code, it will default to the middle of the cell. Your coding will look like this (with new elements here in bold again):

<html>
<head>
<title>Graphics on the Web</title>
<body text="#000000" link="#993333" vlink="#993333" alink="#330000" bgcolor="#fffffff" >
<table width=615 border=0><tr><td>
<h2 align="center">The Baughman Center</h2>
<table><tr><td valign="top">
<p>The University of Florida <a href="baughman3.html">Baughman Center</a> is located on the west bank of Lake Alice. The thumbnail photo of the Baughman Center, at right, is a link to a view of the center from Lake Alice's observation deck near Cory Village.</p>
</td>
<td>
<a href="baughman3.html"><img src="thumbbaughman3.gif" width=60 height=60 border=1 alt="The Baughman Center"></a>
</td></tr></table>
</td></tr></table>
</body>
</html>

If you want the tables you create to be visible, like this, designate the border width to 1 or the number of pixels wide you want the border to be. This outside table is set at 1.
The table nested in the cell to the right has a border of 10 pixels. <table border=10 width=296>

Border is set at 10.

Spacing is set at 2.

Padding is set at 1.

..

Here's the nested table with cell spacing set at 5. Notice how the size of the internal borders expand. The default is 2 pixels, so cell spacing only needs to be designated if you want it to be more or less than 2 pixels.
<table border=10 cellspacing=5 width=296>

Border is set at 10.

Spacing is set at 5.

Padding is set at 1.

..

Here's the same table with padding set at 5. Notice how the text is moved 5 pixels away from the edge of the borders. The default is 1, so cell padding only needs to be designated if you want it to be more or less than 1 pixel.
<table border=10 cellpadding=5 width=296>

Border is set at 10.

Spacing is set at 2.

Padding is set at 5.

..

Designing a Web page requires careful planning of the tables needed to control placement of elements.

Now try this same exercise in Dreamweaver.

Go to Planning Web Tables

Back to top

Back to Projects Index

Back to Schedule