| |
Table Tags
Tables can be used for formatting text into columns, displaying pictures
in rows and columns or for displaying a real table.
Basic elements of Table Tags |
<table>...</table>; | to start and end the table |
<th> ... </th> | table header |
<tr> ... </tr> | table row |
<td> ... </td> | table data or cell definition |
<caption> ... </caption> | table caption (optional) |
- basics of a table
- Tables are made from rows and columns. The rows are defined with the <tr> as mentioned above. The number of columns is determined by the number of <td> tags following each row command.
example table
heading 1 |
heading 2 |
heading 3 |
data 1 |
data 2 |
data 3 |
|
example table
heading 1 |
heading 2 |
heading 3 |
---|
data 1 |
data 2 |
data 3 |
|
- OPTIONS
- There are several options to change the look of a table. Some of these options (specifically bgcolor) are HTML 3.2 and might not show up on your browser if it is not a recent update. Netscape 3.0b4 does work on all the options discussed below.
border=# | changes the thickness of the line around the table |
bgcolor=# | changes the background color of the table or cell |
colspan=# | allows a cell to span # of columns |
rowspan=# | allows a cell to span # of rows |
width=# | changes the width of the table or a column |
height=# | changes the height of the table or a row |
cellspacing=# | adds thickness to the space between the cells |
cellpadding=# | adds whitespace between the cell data and the border |
align=# | horizontally aligns the text either left, center, or right |
align=# | aligns the caption either
top or bottom |
valign=# | vertically aligns the text either top, middle, bottom, baseline |
- border [other options]
- Tables are often used without the knowledge of the reader. Most of this tutorial
is split up on the left and right sides with examples and display of example.
The table itself is not shown because the border around the table is not displayed.
To display a border you need to add the border=# descriptor to the
table start tag. Where the # refers to the thickness in pixels.
- background color [other options]
- You can change the color that is the background for the table.
Tables may be nested and this tutorial does use nested backgrounds. So in this example the nested table should have a red background. To change the background color of a table, you need t
o add the bgcolor=# descriptor to the table start tag. You may also change the background color of a cell by adding a bgcolor=# descriptor to the <th> or <td> tags.
- column span [other options]
- There will be times that you need a data to span two or more columns. To accomplish this use the colspan=# command within the th or td tags.
heading |
1 |
2 |
3 |
4 |
under 123 |
under 4 |
|
heading |
1 | 2 | 3 | 4 |
under 123 | under 4 |
|
- row span [other options]
- Similarly, there may be instances that you need a data to span two or
more rows. To accomplish this use the rowspan=# command within the th or td tags.
- width [other options]
- Sometimes it is necessary to specify the width of either an entire
table or just a column. If you have several tables within one HTML
document, it would probably look a little tacky if they were all
different widths. To gain a more uniformed look, you
could use the width=# descriptor to change either the
table or the cell data tags.
- A width=# tag within the table tag will set the table width to the specified # of pixels. The column widths are not necessarily evenly distributed.
- height [other options]
- A height=# tag within the table tag will set the table width to the specified #. The row heights are not necessarily evenly distributed.
- cellspacing [other options]
- Cell spacing creates additional space between each of the cell blocks.
This could help separate larger tables where the columns and rows
tend to blend together as you try to follow a line across the screen.
The cellspacing=# command should be included with the initial <table> tag.
head 1 |
head 2 |
head 3 |
one |
two |
three |
|
head 1 | head 2 | head 3 |
one | two | three |
|
- cellpadding [other options]
- Cell padding creates additional space between the data and
the cell borders. The cellpadding=# command should be
included with the initial <table> tag.
head 1 |
head 2 |
head 3 |
one |
two |
three |
|
head 1 | head 2 | head 3 |
one | two | three |
|
- horizontal alignment of text
[other options]
- Within each cell you may choose to align the text differently.
To horizontally align the text, the align=# command must reside
within the tr, th, or td tags.
The three
current options are left, center, and right.
head 1 |
head 2 |
head 3 |
one |
two |
three |
|
head 1 | head 2 | head 3 |
one | two | three |
|
- align with captions [other options]
- The align tag can also be used with the caption tag. The default is top with the other option being bottom.
example table
heading 1 |
heading 2 |
heading 3 |
---|
data 1 |
data 2 |
data 3 |
|
example table
heading 1 |
heading 2 |
heading 3 |
---|
data 1 |
data 2 |
data 3 |
|
- vertical alignment of text [other options]
- Within each cell you may choose to align the text differently. To vertically align the text the align=# command must reside within the tr, th, or td tags.
The four current options are top, middle, bottom, and baseline.
head 1 |
head 2 |
head 3 |
head 4 |
one |
two |
three |
four |
|
head 1 | head 2 | head 3 | head 4 |
one | two | three | four |
|
last modified
December 20, 2011
43370
|