[HTML]

Tables

Important tags and attributes:
<TABLE...>, <TH>, <TR>, <TD>
BORDER, CELLSPACING, CELLPADDING
COLSPAN, ROWSPAN, WIDTH
ALIGN, VALIGN

Tables have straightforward uses for displaying tabular information but they can also be used for various layout effects (e.g. see [text]). Tables are "clever" in that the browser will attempt to lay them out "nicely" depending on the size of the elements within a table's cells. The author can give the browser advice by setting the width of a table, or parts of a table, either to absolute values or to fractions (%) of the page width. The contents of a table's cell can be aligned horizontally and vertically (VALIGN). The table itself can also be aligned - left, right, centre - on the page.


Tabular Information

ChildMotherFather
CharlesElizabethPhillip
AnneElizabethPhillip
EdwardElizabethPhillip
AndrewElizabethPhillip
WilliamDianaCharles
HenryDianaCharles

COLSPAN and ROWSPAN

tall
thin
cell
long cell
AB
CD
How was the following done? (Without using [view source].)
ab
cd
e

WIDTH

Try resizing the window for this example.
TABLE WIDTH=60%
WIDTH=20%WIDTH=40%

This table has absolute widths:
TABLE WIDTH=500
WIDTH=100WIDTH=400

WIDTH=800, try giving it less
Cell's WIDTH=400 The cell's WIDTH is set to 400 also
Does it cause scrolling?

For printing tests:

-
WIDTH=500

-
WIDTH=550

-
WIDTH=600

-
WIDTH=650

-
WIDTH=700

600
-|
610
-|
620
-|
630
-|
640
-|
650
-|
660
-|
670
-|
680
-|
690
-|
700
-|
600
20 20 20 20 20

600
-
20
-
20
-
20
-
20
-
20
-


ALIGN and VALIGN

VALIGN=top
ALIGN=center
VALIGN=bottom
ALIGN=left
VALIGN=middle
ALIGN=right
VALIGN=top
ALIGN=right

This table is aligned right but the contents of its cells are aligned in various ways relative to the cell boundaries.



CELLPADDING and CELLSPACING

CELLPADDING:
CELLPADDING=20

CELLSPACING:
CELLSPACINGis
set to10


Copyright © L. Allison, Department of Computer Science, Monash University, Australia 3168 / 1997