
| You are here: NetStrider » Tutorials » HTMLRef » TABLES » |
|
|
||||
| <CAPTION> | <COL> | <COLGROUP> | <TABLE> | <TBODY> |
| <TD> | <TFOOT> | <TH> | <THEAD> | <TR> |
| Introduction |
Tables can be used to precisely position text and objects within an HTML Document.
Tables consist basically of data cells, which consitiute the columns,
arranged in defined rows. The number of rows and data cells within the rows
determine the layout of the table. Table layout is remarkably similar to the layout
of cells within an ordinary spreadsheet.
In addition to rows and data cells tables can also contain headers and a caption. The basic command structure for building a simple table is shown below: |
| Column A | Column B | Column C | ||||||
| Begin | <TABLE> |
|||||||
| Caption |
|
|||||||
| Headers | <TR> |
|
</TR> |
|||||
| Row 1 |
<TR>
|
|
</TR>
|
|||||
| Row 2 |
<TR>
|
|
</TR>
|
|||||
| Row 3 |
<TR>
|
|
</TR>
|
|||||
| End | </TABLE> |
|||||||
|
This table consists of four defined rows. Note that one of the rows contains
headers while the remaining three contain only data cells. The table
also contains a caption.
When defining tables is is essential that the number of data cells within each row match precisely. The browser will always assume that the number of columns (data cells) within each row is constant. If a row has a larger or smaller number of columns (data cells) defined within it than do other rows, then the browser will adjust the entire table display in an effort to reconcile the discrepancy. This can produce some very odd results. Tables can be designed, however, in a way that allows data cells to span either a number of rows or a number of columns. This maintains a constant number of data cells per row but accommodates merging of data cells to accomplish the kinds of effects shown below: Examples of Tables with Merged Cells:
|
|
|
|||||||
| Using advanced table formatting capabilities it is possible to produce almost any arrangement of text and images within an HTML Document. However, table data cells cannot yet be loaded dynamically independent of other data cells. All elements of a table constitute a single object and must load completely before the table can be displayed by the browser. Dynamic content changes within HTML Documents can only be accomplished using frames at present. |
| <CAPTION> Command |
|
Command Syntax:
<CAPTION command parameters>
Sets a table caption. The caption will appear outside any
borders set on the table.
See also: <TABLE>
align="left|right|center|top|bottom"
Where:
Netscape Specific:
valign="top | bottom"
Where:
<CAPTION align="center">Table Caption</CAPTION>
Places the Table Caption above the table (by default) and centered over it.
<CAPTION align="bottom"><CENTER>Table Caption</CENTER></CAPTION>
Places the Table Caption below the table but the included
<CENTER> command also
permits it to be centered, as well, which would otherwise not be possible since
only one alignment parameter is possible within the
<CAPTION> command. |
||||
| <COL> Command |
|
Command Syntax:
<COL command parameters>
The <COL> command
defines the characteristics of a <TABLE>
column in the Internet Explorer browser.
See also: <COLGROUP> Command Parameters:
Example:
|
| <COLGROUP> Command |
|
Command Syntax:
<COLGROUP command parameters>
The <COLGROUP> command
defines the characteristics of a group of columns in a <TABLE>
in the Internet Explorer browser.
See also: <COL> Command Parameters:
Example:
|
|||||
| <TABLE> Command | |||||||||||||||||||||||||
Together these elements define a basic table.
See also: <CAPTION>,
<TD>,
<TH>,
<TR>.
Internet Explorer Specific Table Commands:
Command Parameters:
Defines the alignment of the table where:
See also the
Defines width of the outer border of the table. The border width is
expressed as a pixel value. A border value of 0 (the default)
produces a table with no borders.
The border parameter forces borders on all cells within a table.
The outer border takes on the width specified. All inner table borders are
rendered by various browsers as one or two pixels wide, regardless.
The
The Internet Explorer browser also supports the
Defines the location of a background image for use globally within the table.
The image will tile behind the table and obscure any underlying page background color
or image. Obviously, this and the
bgcolor="color name | color value"
Defines the background color of the table expressed either as
one of the named colors or as a
hexadecimal color value.
Defines the color of the principal border or the highlighted and shaded sides, respectively, of the
table external borders. Color can be expressed either as
one of the named colors or as a
hexadecimal color value.
Only Internet Explorer browser supports these parameters.
Defines the amount of white space or standoff between the margin of the table
data cells and the included text and/or objects. The standoff is expressed as a pixel
value.
Defines the amount of white space or gutter between table
data cells. The gutter is expressed as a pixel
value.
Defines the characteristics of the table borders, if they are set.
Allowable values are:
This parameter is used only in the Internet Explorer browser at present.
See also the
Defines the height and/or the width, respectively, of the table either as an absolute pixel value or
as a percent of the available display width.
Using a percent allows
the table to expand or contract depending on the user's screen resolution.
This is always safe with the width paramenter since available display width
is always defined.
Using a percent
in conjunction with the height parameter can cause curious display effects.
The amount of available vertical display space may not be known to the browser
unless the table is confined within a predefined
space.
Using absolute pixel values forces precise placement and display of table elements
but can result in tables which may have regions which lie outside the viewing area.
Defines the characteristics of the table internal borders or rules, if they are set.
Allowable values are:
This parameter is used only in the Internet Explorer browser at present.
See also the
Defines the vertical alignment of the table within the available display space.
This can be useful in setting the location of the table with respect to text which
may wrap alonside the table.
Clearly, the table must be enclosed within a predefined vertical display space in
order for this command parameter to work properly.
See also the
Example Table Layout:
Note that even without using any command parameters other than those
within the basic table command, the browser is able to parse
and display a reasonable table using defaults within the space
available.
|
| <TBODY> Command |
|
Command Syntax:
<TBODY>
Provides a container for the table body segment.
Has no visible effect on the content of the table but allows special formatting of
borders.
This command is interpreted only by the Internet Explorer browser.
|
| Command Parameters: None. |
Example:
|
| <TD> Command |
|
Command Syntax:
<TD command parameters>
Defines a data cell within a table row.
The number of data cells within a defined table row determines the number of columns that
the row spans. All table rows must have the same number of data cells.
A table data cell is a world unto its own. Only default display characteristics
for the entier document apply within any given cell. Any special formatting desired
must be set up individually cell by cell within a table unless a style sheet
is being used. At present only Internet Explorer browser supports the use of
style sheets.
See also: <TABLE>
|
Command Parameters:
|
|||||||||||||||||||||||||||||||||||
Examples:
|
|||||
| <TFOOT> Command |
|
Command Syntax:
<TFOOT>
Provides a container for the table footer segment.
Has no visible effect on the content of the table but allows special formatting of
borders.
This command is interpreted only by the Internet Explorer browser.
|
| Command Parameters: None. |
Example:
|
| <TH> Command |
|
Command Syntax:
<TH command parameters>
Defines a header cell within a row of table headers.
Any text placed within a header cell is automatically bolded in
most browsers.
See also: <TD>
|
Command Parameters:
|
Example:
|
||||
| <THEAD> Command |
|
Command Syntax:
<THEAD>
Provides a container for the table header segment.
Has no visible effect on the content of the table but allows special formatting of
borders.
This command is interpreted only by the Internet Explorer browser.
|
| Command Parameters: None. |
Example:
|
| <TR> Command |
Command Syntax:
Defines a table row. A table row can consist of
header or data cells. Generally these element types
are not mixed within a table row.
Although the <TR>
can make use of command attributes identical to those used for the
<TD> and
<TH> commands,
parameters are generally not set at the table row level.
|
Command Parameters:
|
Example:
|
||||