|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Adding a BorderYou can place a border around your table by using the BORDER attribute of the <TABLE> tag. BORDER is set to the number of pixels wide you want the border to be. A version of our real estate search table with a 4-pixel border is shown in Figure 6.6. The modified <TABLE> tag that accomplishes this effect is <TABLE WIDTH=100% BORDER=4> You can also set BORDER equal to zero. This means that no border will be used and the browser should give back any space it has reserved to put in a border. This is an especially good approach to use when youre using a table to position page elements because it enables you to place the elements right up against one another without any one- or two-pixel gutters between them. Spacing Within a CellThe distance between the content of a cell and the boundaries of the cell is called cell padding. The CELLPADDING attribute of the <TABLE> tag enables you to control the amount of cell padding used in your tables. Typically, Web page authors increase the cell padding from its default value of 1 to put a little extra whitespace between the contents and the edges of a cell (compare the two tables shown in Figure 6.7). This gives the whole table a bit more room to breathe. The <TABLE> tags used to produce the tables in Figure 6.7 are <TABLE WIDTH=100% BORDER=2 CELLPADDING=6> ... </TABLE> <TABLE WIDTH=100% BORDER=2 CELLPADDING=12> ... </TABLE>
Spacing Between CellsYou also have control over the amount of space between cells. By increasing the value of the CELLSPACING attribute of the <TABLE> tag, you can open up a table even further (see Figure 6.8). Notice that the size of the border used between the cells increases as you increase the cell spacing. The <TABLE> tag used in Figure 6.8 is <TABLE WIDTH=100% BORDER=2 CELLSPACING=8>
Spanning Multiple Rows or ColumnsBy default, a cell occupies or spans one row and one column. For most tables, this is sufficient. When you start to use tables for layout purposes, though, youll encounter instances where you want a cell to span more than one row or column. HTML 4.0 supports attributes of the <TH> and <TD> tags that permit this effect. Using the COLSPAN AttributeThe COLSPAN attribute inside of a <TH> or <TD> tag instructs the browser to make the cell defined by the tag take up more than one column. You set COLSPAN equal to the number of columns the cell is to occupy. COLSPAN is useful when one row of the table is forcing the table to be a certain number of columns wide, and the content in other rows can be accommodated in a smaller number of columns. Figure 6.9 shows a table that makes good use of the COLSPAN attribute. In the figure, the author used the COLSPAN attribute to get the page header (navigation links, sidewalk.com logo, and the date) to occupy three columns of the table.
Using the ROWSPAN AttributeROWSPAN works in much the same way as COLSPAN, except that it enables a cell to take up more than one row. Figure 6.10 shows the international links sections of the Netscape NetCenter page. The Professional Connections link is in a single cell that spans eight rows (ROWSPAN=8) of the table. The HTML code to place the link might look like <TABLE> <TR> <TD> ... contents of first cell ... </TD> <TD> ... contents of second cell ... </TD> <TD ROWSPAN=8><A HREF=prfcon.html>Professional Connections ...</A></TD> </TR> ... </TABLE> What Elements Can Be Placed in a Table Cell?HTML tables were developed with the intent of presenting columns of information, but that information does not necessarily have to be text based. You can place many types of page elements in a given table cell:
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |