|
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." Albert Einstein |
Formatting using tables
Written and HTML encoded by :)Ali
A table starts with the
<table> tag, and ends with a
</table>, then you need to code for each row by
<tr>
and each cell by
<td>
Remember that tables start being built from the top left hand corner, across the colums of the first row, then to the second row, across the colums of the second row.... and so on.
![]() |
|
<table border=1> <tr><th colspan=3> Header Row</th></tr> <td>row 1 col 1</td> <td>row 1 col 2</td> <td>row 1 col 3</td> </tr>
<tr>
<tr> |
| ||||||||||||
![]() |
![]() |
Each <td></td> tag can contain any other type of HTML tag - headers, styled text, coloured text, hypertext links, graphics etc. Within this tag you can also use several attributes to control the alignment of items in a single cell:
| Horizontal Alignment | Vertical Alignment |
|---|---|
| <td align=left> aligns all elements to the left side of the cell (this is the default setting) | <td valign=top> aligns all elements to the top of the cell |
| <td align=right> aligns all elements to the right side of the cell | <td valign=bottom> aligns all elements to the bottom of the cell |
| <td align=center> aligns all elements to the centre of the cell | <td valign=middle> aligns all elements to the middle of the cell (this is the default setting) |
You can combine these attributes. For example:
![]() |
| Header Row | row 1 col 1 | row 1 col 2 | row 1 col 3 |
|---|---|---|
| row 2 col 1 | row 2 col 2 | row 2 col 3 |
| row 3 col 1 | row 3 col 2 | row 3 col 3 |
normally takes up as much space across the page as it needs to.
By adding a width specification into the <table> tag like this: <table width="100%"> you can get it to stretch right across the page:
| Header Row | row 1 col 1 | row 1 col 2 | row 1 col 3 |
|---|---|---|
| row 2 col 1 | row 2 col 2 | row 2 col 3 |
| row 3 col 1 | row 3 col 2 | row 3 col 3 |
A tag of <table width="50%"> would allow the table to take up 50% of the page width, and so on.
You can also use an "absolute" tag, eg <table width="250">, which means it is 250 pixels wide, which looks like.......
| this! |
![]() |
|
<table border=1> <tr><th colspan=3> Header Row</th></tr> <td width="50%">row 1 col 1</td> <td>row 1 col 2</td> <td>row 1 col 3</td> </tr>
<tr>
<tr> |
|
||||||||||||
![]() |
|
which doesn't look very elegant. |
You can make it look much better by using the <table cellpadding=X> tag:
|
<table border=1 cellpadding=10> <tr> <td>like this</td> </tr> </table> |
|
.... which puts a layer of "padding" (blank space) around the text in each cell - in this case it's 10 pixels wide, but you can change the number up or down to get more or less blank space.
![]() |
|
<table border=1 cellspacing=10> <tr> <td>like this,</td> </tr> </table>
<table border=1 cellspacing=10>
<table border=1 cellspacing=10>
<table border=1 cellspacing=10> |
This is using the <cellspacing=10> tag:
|
||||
|
compare this with the <table border=10> tag!
|
With the <table border=X>, <table cellpadding=X> and <table cellspacing=X> tags, X can have any value you like. The higher the number, the wider the border, padding or spacing.
![]() |
|
<table border=1 cellpadding=5> <tr> <td colspan=3 align=center>merging three columns</td> </tr>
<tr>
<tr> |
|
||||||||
![]() |
|
<table border=1 cellpadding=5> <tr> <td>
<table border=1 cellpadding=5>
<tr> |
|
Now you've got it sussed! Just remember that you need to put the little table INSIDE the <td></td> tags of the bigger table - and don't forget to close all your tags!