Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Creating a Simple Table

To make tables, you have to start with a <table> tag. Of course, you end your tables with the </table> tag. If you want the table to have a border, use a border attribute to specify the width of the border in pixels. A border size of 0 (or leaving the border attribute out entirely) will make the border invisible, which is often handy when you are using a table as a page layout tool.

With the <table> tag in place, the next thing you need is the <tr> tag. <tr> creates a table row, which contains one or more cells of information before the closing </tr>. To create these individual cells, you use the <td> tag. <td> stands for table data; you place the table information between the <td> and </td> tags.

A cell is a rectangular region that can contain any text, images, and HTML tags. Each row in a table is made up of at least one cell.

There is one more basic tag involved in building tables: The <th> tag works exactly like a <td> tag, except <th> indicates that the cell is part of the heading of the table. Some Web browsers render <th> and <td> cells exactly the same, but Netscape Navigator and Microsoft Internet Explorer (version 4 or greater) both display the text in <th> cells as centered and boldface.

You can create as many cells as you want, but each row in a table should have the same number of columns as the other rows. The example in Figures 15.1 and 15.2 shows a simple table using only these four tags.

15fig01.gif

Figure 15.1 The <table>, <tr>, and <td> tags are all you need to create simple tables. The <th> tag can also be used to specify a heading.

15fig02.gif

Figure 15.2 The HTML in Figure 15.1 creates a table with four rows and three columns.

You can place virtually any other HTML element into a table cell. However, tags used in one cell don't carry over to other cells, and tags from outside the table don't apply within the table. For example, if you wrote the following, the word there would be neither boldface nor italic because neither the <b> tag outside the table nor the <i> tag from the previous cell affects it:

<b>
<table><tr>
 <td><i>hello</td>
 <td>there</td>
</tr></table>
</b>

To make both the words hello and there boldface, you would need to type this:

<table><tr>
 <td><b>hello</b></td>
 <td><b>there</b></td>
</tr></table>

Share ThisShare This

Informit Network