This lesson will have a lot of information in it, so pay close
attention. There are many tags and attributes for you to
remember, so we will have tons of examples. The main tags to
keep in mind are the <table> , <tr> , and <td>
tags. A simple table is set up like this (remember to indent
your code!):
<table>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
This is a very simple table and easy to make.
I bet that if you didn't organize your code though, you would
have some trouble. The first attribute to learn is the
alignment attribute. it is the same as for the paragraph tag.
<table align="center">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
The default for the align attribute is left. The values can
be left, right, or center. The table tag has many more
attributes such as follows.
<table align="center" border="1"
bordercolor="#000000" cellspacing="0"
cellpadding="0">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
The following explains all the attributes and possible values:
Attribute |
Description of the attribute |
align |
where the table is positioned on
the screen (right, left, or center) |
border |
The thickness of the border. A
border of "0" is invisible. |
bordercolor |
specifies the solid color of a
border |
cellspacing |
amount of space between each cell |
cellpadding |
amount of space between a cell
border and the contents of the cell |
bordercolorlight |
the color of the light part of a
three dimensional border |
bordercolordark |
the color of the dark part of a
three dimensional border |
bgcolor |
the background color |
background |
the location of a picture to tile
as a background. |
width |
the width of a table in pixels or
percent of the screen |
height |
the height of the table in pixels.
Not the percent of the screen. |
If you use bordercolorlight and bordercolordark, you should not use
bordercolor. This also applies for bgcolor and background.
As you can see, there are many attributes. You most likely will
not use cellspacing or cellpadding. I don't expect you to
remeber all of these right away. Now for the in-depth look at these
tags. The table tag tells the browser to create a table.
The table row tag (<tr> ) tells the browser to begin a new table
row. The cell tag (<td> ) tells the browser to make a new
cell. Cells also have attributes of there own. For
example:
<table>
<tr>
<td bgcolor="blue">blue</td>
<td bgcolor="red">red</td>
</tr>
</table>
Many attributes are the same as the table attributes, but not all.
Attribute |
Description |
bgcolor |
the background color |
background |
the location of a picture to be
tiled as a background |
height |
height of a cell in pixels or in
percent in relation to the height of the table. |
width |
the width of a cell in pixels or
in percent in relation to the width of the table. |
colspan |
the number of columns a merged
cell takes up |
rowspan |
the number of rows a merged cell
takes up. |
Colspan and rowspan are more advanced. It may take some time
to learn these.
<table>
<tr>
<td rowspan="3">cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
<tr>
<td colspan="3">cell 5</td>
</tr>
<tr>
<td colspan="3">cell 6</td>
</tr>
</table>
cell 1 |
cell 2 |
cell 3 |
cell 4 |
cell 5 |
cell 6 |
This may look complex, but you shouldn't use it much. We are ready for another
sample web page. Here is a link to a text
file with the code in it. Save this page as table.html.
It
is ok to copy the code from the screen with a text file link. You can also right click
on the link and select 'save target as'. If you copied the code
correctly, it
should look like this. You should understand all the code in
the above example before we move on. Tables can come in
handy. Most web pages are laid out in invisible tables (like
this site). An invisible table has the border attribute set to
zero ("0"). If you plan to lay out your whole web site
in tables, you may need to draw a plan first of how you want it
to look.
|