Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Alignment and Spanning

By default, anything you place inside a table cell is aligned to the left and vertically centered. You can align the contents of table cells both horizontally and vertically with the align and valign attributes.

You can apply these attributes to any <tr>, <td>, or <th> tag. Alignment attributes assigned to a <tr> tag apply to all cells in that row. Depending on the size of your table, you can save yourself a considerable amount of time and effort by applying these attributes at the <tr> level and not in each individual <td> or <th> tag. The HTML code in Figure 15.3 uses valign="top" to bring the text to the top of each cell. Figure 15.4 shows the result.

15fig03.gif

Figure 15.3 You can use alignment, cell spacing, borders, and background colors to bring clarity and elegance to your tables.

15fig04.jpg

Figure 15.4 The colspan attribute in Figure 15.3 allows the top-left cell to span multiple columns.

At the top of Figure 15.4, a single cell spans two columns. This is accomplished with the colspan="2" attribute in the <th> tag for that cell. As you might guess, you can also use the rowspan attribute to create a cell that spans more than one row.

Share ThisShare This

Informit Network