|
|
|
In all previous examples, the position of the data within the cell has been left to the default
settings. You can set the alignment of your data within each cell, using the ALIGN
(horizontal alignment) and VALIGN (vertical alignment) attributes.
ALIGN and VALIGN are attributes of the TD and TH tags.
align=left / align=center / align=right
The TH default setting is to the center of the cell.
The TD default setting is to the left of the cell.
valign=top / valign=middle / valign=bottom
The TH default setting is to the middle of the cell.
The TD default setting is to the middle of the cell.
|
If you do not specify the align
or valign attributes, then the data will go to the default settings, which will be different
depending on whether it is a TD or TH cell.
TH defaults: align=middle valign=middle TD defaults: align=left valign=middle |
TH Defaults | th valign=top | th valign=bottom |
|---|---|---|---|
| TD Defaults | td valign=top | td valign=bottom | |
|
td align=center valign=top |
td align=center |
td align=center valign=bottom |
|
|
td align=right valign=top |
td align=right |
td align=right valign=bottom |
ALIGN is also an attribute of the TR tag.
Instead of specifying the alignment attributes within every cell in a table row, you can preset
the alignment for the entire row by specifying ALIGN or VALIGN within the TR
tag.
<tr align=right valign=bottom>
<td>data</td> ... etc ... etc ... etc
| The alignment for the whole row has been specified in the TR tag. | data | data | data |
If you want to have the alignment for one or more of the cells different from the overall
TR alignment setting, then simply specify the alignment you wish within that data cell.
The TD or TH alignment will over-ride the pre-set TR alignment.
<tr align=right valign=bottom>
<td>data</td>
<td align=center valign=middle>data</td>
<td>data</td>
<td>data</td>
</tr>
| The middle cell has it's own alignment specified, which over-rides the pre-set TR alignment. | data | data | data |
ALIGN is an attribute of the table tag.
This determines the position of your table on the page. You can align your table left,
right or center. If you do not specify the alignment,(as in all the previous
examples) it will default to the left.
NOTE: When the align=right or align=left attribute is used, the text that follows the
table will appear at the side of the table.
<table border=5 cellpadding=2 width="30%" align=right>
| Roses | Tulips |
| Orchids | Daisies |
| Asters | Zinnias |
See how this text is forming at the top next to the table? That is just fine....unless you do
not want it that way! I have experimented with lots of different tags, but I cannot find a way
to stop the text from forming beside the table. The only way I have found is to just keep on
writing or put in a string of <br><br> ... etc until you get below the table
and can then carry on as normal!
<table border=5 cellpadding=2 width="50%" align=left>
| Apple | Pear | Mango |
| Peach | Orange | Banana |
You can of course, make use of the text forming to the side of the table! This gives an
interesting layout and make a change from centering everything. Once again, the text continues
down the side of the table until it reaches the bottom margin, then it forms across the whole
page as normal.
You can also use the align=center attribute to center your table, or, you could use the
<center> and </center> tags outside of your table.
<table border=25 cellpadding=2 width="65%" align=center>
| Fiat | Volvo |
| Mercedes | Ford |
| Bentley | Holden |
This time the following text forms below the table, and not down the sides of it.
COLSPAN is an attribute of the TD and TH tags.
You can make your data cells span more than one column by using the colspan attribute.
This can be added to td or th cells.
colspan is expressed as the number of rows or cells, that you want this particular cell
to span.
<table border=5 cellpadding=2 width="50%">
<tr><th colspan=3>Australian Flowers</th></tr>
<tr><td>Waratah</td><td> ... etc ... etc
| Australian Flowers | ||
|---|---|---|
| Waratah | Kangaroo Paw | Wattle |
| Banksia | Sturt Pea | Grevillea |
ROWSPAN is an attribute of the TD and TH tags.
<table border=5 cellpadding=2 width="65%">
<tr><th colspan=4>Australian Animals</th></tr>
<tr><th rowspan=3>What an odd collection of
beasties!!</th><th>Mammals</th> ... etc ... etc
| Australian Animals | |||
|---|---|---|---|
| What an odd collection of beasties!! |
Mammals | Reptiles | Birds |
| Kangaroo | Frill-necked lizard | Emu | |
| Wombat | Crocodile | Kookaburra | |
CAPTION is an attribute of the TABLE tag.
To add a caption to your table, simply insert
<caption> caption text</caption>.
These tags are inserted just after the opening <table> tag.
<table border=5 cellpadding=5>
<caption><b>The Beatles!</b><caption>
| All You Need is Love |
| Eight Days a Week |
| A Little Help From My Friends |
By changing the tag to <caption align=bottom> caption text </caption>,
we can put the caption below the table.
| Pretty Woman | Starman |
| Four Weddings | The Full Monty |
| Strictly Ballroom | Legends of the Fall |