[Index of Lessons]
[Advanced Lesson 6]
[Advanced Lesson 8]
[Colour Page]

A7. Tables

Tables
Tables were introduced into HTML 3.0 and further enhanced by Netscape to add another dimension to web page design. They provide a structure for organizing other HTML elements into "grids" on the page. One of the more obvious uses of tables is when you have to format... columnar tables of text! But, tables also open up the door for many other page layout options.

The whole html code of tables basically has only 3 tags...

<TABLE> The main tag. Used to tell the browser "this is a table", along with some attributes like size,border width and a few other things.
<TR> TableRow defines a horizontal row of <TD> cells.
<TD> TableData specifies an indiviual block or cell in a table row.

Tables
HTML Result
<table border=1>
<tr>
 <td>Col 1 Row 1</td>
 <td>Col 2 Row 1</td>
</tr>
<tr>
 <td>Col 1 Row 2</td>
 <td>Col 2 Row 2</td>
</tr>
</table>
Col 1 Row 1
Col 2 Row 1
Col 1 Row 2 Col 2 Row 2
Well as you have seen the table tag can have a border, a border gives the table visable gridlines, it is also possible to have a table without gridlines, this is done by having the border attribute set to zero, eg <table border=0> You can make the border any thickness you like ranging from 0 to 25, most border's are set around the numbers 0,1,2 and 3.
There are also other commands which can be placed within the Table tag, these are height,width, align=left and align=right. To center a table, I have found it easier just to place the <center>...</center > tags around the whole table. Below are a list of <table...> tags :

Tables - Table Tags
HTML Range
<table border=1>
<table width=25>
<table height=50>
<table align=right>
<table align=left>
<table cellpadding=12>
<table cellspace=12>
<table bgcolor=green>
0...100
0..100 or 0%..100%
0..100


0..20
0..20
for full range of colours go to the top of the page and click on the Colour page link
Well now that you have seen all of the attributes that can be used with in the <table..> tag, I'd better explain them to you,

Border
This attribute changes the thickness of the border around a table, 0 being that there is no visable border and 100 being just a silly width, normal table border's don't go above 20, and here's an example of border thickness for you :

Border=1

Border=10

Width
Width changes the width of the table in comparision to the viewer's screen, it has two different forms of settings, it can be in pixels or in a percentage form, in pixel form the table would have a specific width, whereas with the percentage form the table will adjust it's self to fit it's percentage. Examples (Will have border=1 so you can actually see the tables):

Width=70

Width=70%

Height
Height changes the height of a table in comparision to the viewer's screen, it has only the one form of settings, it is in pixels. In pixel form the table will have a specific height. Here's an example (Will have border=1 so you can actually see the table):

Height=70

Align (right or left)
Alignment changes the position of a table in comparision to the viewer's screen, it has two forms of settings. These are align=left or align= right. Align left places a table on to the left side of the viewer's screen whereas align=right places the table on the right hand side of the screen. To get a table into the middle of the screen, just place the <center>...</center> tags around it. Here's some examples (Will have border=1 so you can actually see the table):

Left
Right

Center

Cellpadding
Cellpaddig is the amount of space between the border of a cell and the contents of the cell. Here's some examples (Will have border=1 so you can actually see the table):

Cellpadding=12

Cellpadding=2

Cellspacing
Cellspacing is the amount of space between the content borders of a cell and the external border. Here's some examples (Will have border=1 so you can actually see the table):

Cellspacing=12

Cellspacing=2


Okay, as you can see a table can be modified in many different ways within the table tag. All of these commands can be combined in different manners,
ie <table width=75% height=60 cellpadding=10 cellspacing=10 border=5 align=right>
Though normally they aren't all used at once. Some of these commands can also be repeated on the individual TableData tags (<TD>). Here's a list of them :

Tables - TD Tags
HTML Range
<td width=25>
<td height=50>
<td align=right>
<td align=left>
<td align=center>
<td valign=top>
<td valign=bottom>
<td valign=middle>
<td colspan=2>
<td rowspan=2>
<td bgcolor=green>
0..100 or 0%..100%
0..100





1..#of columns in table
1..#of rows in table
for full range of colours go to the top of the page and click on the Colour page link
Well now that you have seen all of the attributes that can be used within the <td..> tag, I'd better explain them to you,
But to make life a little easier I'll show you a table modifcation, one table at a time. First off lets make a standard table with six cells, a table of two rows and three columns. :

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td>Bubble</td>
   <td>Gum</td>
   <td>Crisis</td>
  </tr>
  <tr>
   <td>Sylia</td>
   <td>Nene</td>
   <td>Priss</td>
  </tr>
  </table>
Bubble Gum Crisis
Sylia Nene Priss
Width and height
As you can see the table automatically makes and adjust all the variables of the simple table. Now lets change some parts of the table, first on the list is width. We'll modify the width of Row 1 Col 1 "Bubble" and next on the list is height, we'll modify the height of Row 2 Col 3 "Priss" . Let's give the first one a width of 160 and the second modification a height of 50. Note that the modification of height on one cell does effect the height of all cells in that row. :

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td width=160>Bubble</td>
   <td>Gum</td>
   <td>Crisis</td>
  </tr>
  <tr>
   <td>Sylia</td>
   <td>Nene</td>
   <td height=50>Priss</td>
  </tr>
  </table>
Bubble Gum Crisis
Sylia Nene Priss
Horizontal Alignment
As you can see the table shape has been heavily modified by adjusting the height or width of a td tag. Now it's time to show you the alignment of tags you can use within the td tag. First off we'll modify the width and height of Row 1 Col 1 "Bubble" and also modify the width and height of Row 2 Col 3 "Priss". We'll give them a height and width of 100, in this way we will have a couple of large boxes within the table to work with.
Once that has been achieved, it's time to start setting the alignment of a few cells. Notice how that all the text is automatically centered in the vertical section, this can be changed, but first lets work on the horizontal allignment.
Lets move to the right, Row 1 Col 3 "Crisis", we'll center, Row 2 Col 1 "Sylia" and even though it is standard alignment, we'll align Row 1 Col 1 "Bubble" to the left.

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td width=100 height=100
   align=left>Bubble</td>
   <td>Gum</td>
   <td align=right>Crisis
   </td>
  </tr>
  <tr>
   <td align=center>Sylia
   </td>
   <td>Nene</td>
   <td width=100 height=100> 
   Priss</td>
  </tr>
  </table>
Bubble Gum Crisis
Sylia Nene Priss
Vertical Alignment
The addition of alignment allows for a table to be made to look much more professional. Now it's time to show you some more of the alignment of tags you can use within the td tag. First off we'll modify the width and height of Row 1 Col 1 "Bubble" and also modify the width and height of Row 2 Col 3 "Priss". We'll give them a height and width of 100, in this way we will have a couple of large boxes within the table to work with.
Once that has been achieved, it's time to start setting the alignment of a few cells. Remember how all the text is automatically centered in the vertical section, this can be changed and now, I'll tell you how to do it.
Lets change the position of Row 1 Col 3 "Crisis" to the top of the cell, we'll put Row 2 Col 1 "Sylia" on the bottom of the cell and lastly we'll align Row 1 Col 1 "Bubble" to the center of the cell, though it may just look like a horizontal alignment.

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td width=100 height=100
   valign=middle>Bubble
   </td>
   <td>Gum</td>
   <td valign=top>Crisis
   </td>
  </tr>
  <tr>
   <td valign=bottom>Sylia
   </td>
   <td>Nene</td>
   <td width=100 height=100> 
   Priss</td>
  </tr>
  </table>
Bubble Gum Crisis
Sylia Nene Priss
Colspan and Rowspan
As you have seen, the width and height of a cell can be modified to whatever you want. Now there is an attricute that enables data to be in more than one cell, either horizontally or vertically. These tags are the Colspan and Rowspan tags. The use of these tags is going to modify our table in a drastic fashion. In our current table (6 cells) the first row "Bubble", "Gum", "Crisis" is the heading and it looks unprofessional having them separated like they are, to fix this we'll use the colspan tag. Just so I can show you the rowspan tag as well, I'll increase the size of the table by another row and add in some more data. What I'll do for Rowspan is I'll increas the rowspan of the middle cell Row 2 Col 2 "Nene". Also note, How I haven't modified the actual width or height of the table, making it a smaller and more managable table.

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td colspan=3>
 Bubble Gum Crisis</td>
  </tr>
  <tr>
   <td>Sylia</td>
   <td rowspan=2>Nene
</td>
   <tdPriss</td>
  </tr>
  <tr>
   <td>Linna</td>
   <td>Leon</td>
  </tr>	
  </table>
Bubble Gum Crisis
Sylia Nene Priss
Linna Leon
Colspan and Rowspan cont...
An important thing to notice in the rowspan and colspan part of tables is that, originally we had three cells saying "Bubble" "Gum" "Crisis, and when we made the <td colspan=3> call there was only one td in that table row (tr). The same thing occured when using the rowspan call. The third row did not have the normal middle td.
To simplify, if you use colspan to cover the whole length of a table's columns, then you remove all but the one td tag. If you use rowspan, note that you only have to place td tags in the position where you want cells to appear.

Background Colour
Well you have read most of the important things about tables so far, the last thing to discuss in making tables is to have them consist of different colours. A good example of table colours is here :

Tables - TD examples
HTML Result
<table border=1>
  <tr>
   <td bgcolor=red>Bubble
   </td>
   <td bgcolor=blue>Gum
   </td>
   <td bgcolor=green>Crisis
   </td>
  </tr>
  <tr>
   <td bgcolor=gold>Sylia
   </td>
   <td bgcolor=lightblue
   >Nene</td>
   <td bgcolor=white> 
   Priss</td>
  </tr>
  </table>
Bubble Gum Crisis
Sylia Nene Priss
As with HTML code, all of the tags you have seen can be written together or separtely. Therefore you can have a table which has a td tag like...<td width=100 height=100 bgcolor=blue valign=top align=right>Impressive Tag</td>.
It is also possible to have tables within tables, instead of having text after a td tag, you write in the code for a table, always remember to close of all opened tags, ie each <td> has it's matching </td> tags.
Another thing that can happen is that you can have images loaded in place of text within a table. This allows for the positioning of text next to or even around an image if you want, ie text around an image would look like this :

This above the pic
This is to the left This is the pic This is to the right
And this is the last line around the pic, I have the borders set to 1 so you could see the actual shape of the table. With the knowledge you have picked up on this page, you should be able to write the code behind this table.

Example
It is now time to incorporate the example again. Tables are the most important piece of advanced HTML that you will ever learn. This entire site has everything within tables. Why? Because they allow for the text to be aligned and structured properly. So let's modify the original web page once more, but let's change the apperance quite a bit.

<html>
<head>
<title>UFO's, Paranormal and other Mysteries</title>
</head>
<body text=white bgcolor=black link=yellow background="../images/startile.gif" vlink=red>
<table>
<tr>
<td><h1><font color=yellow><u>UFO's, Paranormal and
other Mysteries</u></font></h1></td>
</tr>
<tr>
<td>Welcome to my web site, this site is going to have various
pages pertaining to information I have read and have found very
interesting.<br>
Subject matter will range from UFO's to ghosts and
there specter friends, prophecy's and theories which will make
your mind query all that you know.<p>
All of the information contained within these pages can be found in full in the <b>X-Factor</b> magazine. For these pages only excerpts have been used. All pictures have been found on various web sites around the world.<p>
I hope you enjoy this site<p>
</td>
</tr>
</table>
<table>
<tr>
<td><h1><u>UFO's</u></h1></td>
<td><img src="../images/iran_ufo.gif" width=80 height=60 alt="Iran UFO"></td>
<td width=10> </td>
<td><h1><u>Paranormal</u></h1></td>
<td><img src="../images/nos1.gif" width=68 height=99
alt="Nostradamus pic"></td>
</tr>
<tr>
<td colspan=2 align=left><h3>Area 51</h3></td>
<td> </td>
<td colspan=2 align=left><h3<Millennium</h3></td>
</tr>
<tr>
<td colspan=2><i>"About 190km north west of Las Vegas, in the Nevada
desert, the offical map stops. There is plenty there - roads, creeks,
mountains, bunkers, buildings and a massive 9.5 km runway - but on paper
these things do not exist. It is as if all human activity has ceased
across an area the size of Switzerland."</i></td>
<td> </td>
<td colspan=2><i>"Michel de Nostradame, popularly known by his Latin
name Nostradamus, often spent his evenings alone, gazing into a bowl of
water - like a gypsy with a crystal ball - until he went into a deep
trance and saw into the future. On one such night, Nostradamus witnessed
his own death. He died two weeks later, on 2 July 1566 - the exact date
he had predicted." </i></td>
</tr>
<tr>
<td colspan=2>
<ul>
<li><a href="a51.htm">Main Article</a>
<li><a href="a51.htm#case">Case Notes</a>
<li><a href="a51.htm#profile">Profile</a>
<li><a href="a51.htm#evi">Evidence</a>
</ul></td>
<td> </td>
<td colspan=2>
<ul>
<li><a href="nos.htm">Main Article</a>
<li><a href="nos.htm#case">Case Notes</a>
<li><a href="nos.htm#analysis">Analysis</a>
<li><a href="nos.htm#evi">Evidence</a>
</ul></td>
</tr>
</table>
<p>
<table>
<tr>
<td><h1><u>Mysterious World</u></h1></td>
<td><img align=right src="../images/ark.gif" width=132 height=61
alt="Ark pic"></td>
</tr>
<tr>
<td colspan=2><h3>Quest for the Lost Ark</h3></td>
</tr>
<tr>
<td colspan=2><i>"Covered with gold and surmounted with two golden
Cherubim facing each other, the Ark of the Covenant must have been an
awesome object to behold. But it was what lay inside that made it the
holiest - and most powerful - of religious objects"</i></td>
</tr>
<tr>
<td colspan=2>
<ul>
<li><a href="ark.htm">Main Article</a>
<li><a href="ark.htm#case">Case Notes</a>
<li><a href="ark.htm#profile">Profile</a>
</ul>
</td>
</tr>
</table>
<p>
</body>
</html>

Like before, add all of this to your first web page by opening the document and editing the page. To speed it up, you can cut and paste the code. After you have done all of this, click here (Example 9) to compare your work to the example provided.

As you can quite easily see, the introduction of tables into the main page has made it quite easily to modify the complete structure of the page, it has also improved the general look and feel of the example page.

An important thing to also see is that I have updated the links on the example page so that they will all work. The modifications to these individual files was minimal, and as a small test, try and make your files look the same.

Click on Advanced Lesson 8 to continue, or click here (Top) to return to the top of document