|
Tables
Tables are an extremely popular means of creating more complex web pages. They allow a greater control of structure on a website. All of these pages are tables, with different elements of the tables representing navigation, top bars, and main areas. Simple tables are easy to create:
| HTML Code: | Result: |
<table border=1>
<tr> <td> 1 </td> <td> 2 </td> </tr>
<tr> <td> 3 </td> <td> 4 </td> </tr>
</table> |
|
As you can see, <table> is the tag used to start the table itself. Information such as border width is contained in this tag. The next tag is <tr> which marks the start of a row. This means that </tr> then ends the row, meaning a new one must be started. Finally, <td> represents an individual cell of the table. Between <td> and </td> will be all the information you want to put in a particular cell.
As mentioned, more information such as border width can be contained in the initial tag. The following are useful adjusters:
- <table border=2 bordercolor=#000000> makes a black border of width 2 pixels
- <table bgcolor=#ffffff> makes the background colour of the table become white (the background is normally transparent).
- <table width=X%> makes the table as wide as X% of the page
- <table cellspacing=X> makes the gap between each cell X pixels.
- <table cellpadding=X> makes the gap between cell contents and cell wall X pixels minimum.
- <table align=center> causes the table to be aligned centrally. This part of the tag can be put into a specific element (in the <td> tag) in order to make certain elements become centrally aligned
- <table valign=top> makes the elements of the table move to the top of their cells. This can be made to affect only one cell, or a row of cells in the same way as the alignment above.
Of course, you can use more than one of the above adjusters within the same tag, creating a table of width 20%, with a red border, a green background, with 3 pixel cellspacing, 5 pixel cellpadding, like so:
<table border=1 width=20% bordercolor=#ff0000 bgcolor=#00ff00 cellspacing=3 cellpadding=5>
This could be used to create the following simple table which contains only one elements, labelled X:
Another important adjustment that can be made to tables is the span of each row or column. As set out above, each column has a width of 1, and so do the rows. However, this can be changed:
| HTML Code: | Result: |
<table border=1>
<tr> <td colspan=2> 1 </td>
</tr>
<tr> <td> 3 </td> <td> 4 </td> </tr>
</table> |
|
Similary for rows:
| HTML Code: | Result: |
<table border=1>
<tr> <td rowspan=2> 1 </td> <td> 2 </td>
</tr>
<tr> <td> 3 </td> </tr>
</table> |
|
With a firm grasp on tables, its time to move onto the next tutorial, the use of frames.
|