|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tables |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HTML TablesObjectivesBy the end of this lesson, you will be able to:
Introduction to TablesFrequently you will find that you need to align text and images, horizontally or vertically (or both) on a page. When you want to create the appearance of tabular or structured text, you can use the table tags provided in HTML. Useful and attractive grids can be created with an HTML table. Figure 6-1 describes the individual elements that compose an HTML table. Each of these elements will be explored in this lesson.
The code for the table in the preceding figure could be written as follows:
Table and Data Alignment OptionsFrequently you will want to align cell content in a manner that differs from the default alignment. By default, table header cells are aligned to the center of the cell. Table data cells are aligned to the left by default. As you can see, by default, cell contents are aligned vertically to the middle of the cell. You can change this for an individual cell or for an entire row. The attribute you use to specify horizontal alignment is ALIGN. For vertical alignment, use VALIGN. The example on the left in Figure 6-13 sets the alignment of the entire row to "top," meaning all cell content in that row will start at the top of the cell. The example on the right specifies a vertical alignment only for the cell containing Tahiti . The cell to the right of Tahiti is already aligned to the top because it is completely full, so the appearance generated by either choice will match that shown in Figure 6-14. (The second row was left unchanged for contrast.) So far, you have examined only tables with single lines of cell content. Now consider the example in Figure 9-12. Tour Packages
Figure 9-12: Vertical alignment of cell content [See Figure 9-12 in pop-up broswer for easier HTML code viewing]
You can align the contents of any table cell to the left, right or center. In addition, you can align the table itself relative to the surrounding page text by adding the ALIGN attribute to the <TABLE> tag. Examine Figure 6-15.
Tables can float to the left or right of page text. In Figure 6-16, the page alignment of the table has been changed from left to right.
You also have the option to align the table to the center of the page, as shown in Figure 6- 17.
Table 6-2 outlines the various alignment attributes, and the table elements with which these attributes can be used.
Changing Height and Width of Table ElementsYou can change the height or width of the table and individual cells by specifying pixel or percentage values. Table Width = 450 pixels
Table Width = 90% or 634pixls (in the case of this browser setting)
In the preceding figure, the table rows increased in size because the HEIGHT attribute of the <TABLE> tag was set to "90%", meaning 80 percent of the browser window. Note that the new height was equally distributed among the various rows.
Column and Row SpanningSometimes you will want to apply a heading across several cells. In other cases, you may need one cell to span more than one row. Figure 6-22 demonstrates a cell that horizontally spans three columns, as well as a cell that vertically spans four rows. The table is displayed in an earlier version of the Netscape browser to demonstrate that older browsers support this feature. Figure 9-12: Vertical alignment of cell content [See Figure 9-12 in pop-up broswer for easier HTML code viewing]
The following code demonstrates how this effect is accomplished by using the ROWSPAN and COLSPAN attributes.
<TABLE CELLSPACING=lO WIDTH="lOO%"> <TR><TH COLSPAN=3>Conservation.. .< /TH></TR> <TR><TD ROWSPAN=4><IMG SRC="paloalto.gif"></TD> <TH>Date</TH><TH>Activities</TH></TR> <TR><TD>November 17</TDxTD>Discussion of ... </TD></TR> <TR><TD>November 23</TD><TD>Naturelands hike ... </TD></TR> <TR><TD>December 26</TD><TD>The movie ... </TD></TR> </TABLE>
Most of the attributes and text have been removed to facilitate your focus on key tags. Note the COLSPAN and ROWSPAN attributes in bold and their effects on the table. The COLSPAN attribute value "3" identifies the number of columns that the cell will span. The ROWSPAN attribute value of "4" identifies the number of rows that the cell will span. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||