| Contents Home Revision Tables Colours Styles Javascript |
TablesTables are one of the main ways of controlling layout on a page. You can enclose the entire page in a table (as in this page), or use smaller tables on their own, or nested within bigger tables (as below).
<table border="1">
<caption align="left"><strong>Example Table</strong></caption>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
<tr>
<td bgcolor="#ffff66">Row1 Column1</td>
<td>Row1 Column2</td>
</tr>
<tr>
<td>Row2 Column1</td>
<td>Row2 Column2</td>
</tr>
</table>
Which displays as: -
Note how the browser controls the format of the heading cell. If you want full control of the table appearance use only the <td> tag within tables, and specify the colours and font size etc. yourself. Table AttributesThe table tag can take the following attributes: -
If you want to center your table reliably, then the best method is to enclose it in a division tag: - <div align="center"><table>.....</table></div> Row and Cell AttributesBoth rows and cells can take the following attributes: -
In addition, cells can also specify: -
Complex tablesTables can become complex, with tables within tables or involving cells which span several rows or columns. These are usually best constructed using a WYSIWIG HTML editor, rather than trying to work out the code for yourself. However, if you want to give it a go, make full use of levels of indentation (as shown in Example 2 below) to make it easier to pick out which code belongs to which row or column.
The table above would be coded as: - <table border="1" cellpadding="3" cellspacing="1" width="80%">
<tr>
<td bgcolor="#FFFF66" width="100%" colspan="4"> </td>
</tr>
<tr>
<td width="25%" rowspan="5" bgcolor="#0000FF">
</td>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
</tr>
<tr>
<td width="25%"> </td>
<td width="50%" colspan="2" rowspan="2"
bgcolor="#008000"> </td>
</tr>
<tr>
<td width="25%"> </td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
</tr>
</table>
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||