Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > CLIENT SIDE CODING > HTML TUTORIALS > THE BASICS OF HTML


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

The Basics of HTML
By Ben Sinclair - 2003-01-04 Page:  1 2 3 4 5 6 7 8 9

Tables


What are tables used for?

Tables are used to make data a lot easier to interpret or to just give your document a more professional image.

<table border=4>
<tr>
<th>What are tables used for?</th>
</tr>
<tr>
<td>Tables are used to make data a lot easier to interpret or to just give your document a more professional image. </td>
</tr>
</table>

Here is what it would look like on the page:

What are tables used for?
Tables are used to make data a lot easier to interpret or to just give your document a more professional image.


Tables are one of the most challenging things to code with HTML. It isn't very hard, it just takes a while to get used to it. Tables start with the <table> tag, and usually contain the border=n(number) attribute within the opening tag. If the border=0, than the table's border is invisible. Usually when you do not use the border attribute, the table border will become invisible. This is useful when you want to align text in rows and columns, but don't want a table border around it.

border=1 is a thin border, border=2 is a little thicker, border=3 a little more thicker and so on. The table MUST end with a </table> tag, or the table will not appear at all!

This table has a border of 0.


As you can see in the above example there is no border at all.

And here is the HTML code:

<table border=0>
<tr>
<td>This table has a border of 0.</td>
</tr>
</table>

This table has a border of 3. It is the same code as above, but you change the <table border=0> to <table border=3>

This table has a border of 3.


Each row within the table is defined by the opening <tr> tag and the optional </tr> closing tag. Within each table row are table cells, which are defined by the <td> opening and </td> closing tags. Most table rows contain more than one cell. Many times, you will need a heading for a column of cells of the first row. To do this, you will use the <th> opening and </th> closing tag. The table heading tag makes the text in that cell BOLD and CENTERED. You only need to use the heading cells when necessary.

Here is an example of a table with multiple rows and columns...

Heading A
Heading B
Heading C

Cell A
Cell B
Cell C

Cell D
Cell E
Cell F

Heading AHeading BHeading C
Cell ACell BCell C
Cell DCell ECell F


Here is the HTML code:

<table border=2>
<tr>
<th>Heading A</th><th>Heading B</th><th>Heading C</th>
</tr>
<tr>
<td>Cell A</td><td>Cell B</td><td>Cell C</td>
</tr>
<tr>
<td>Cell D</td><td>Cell E</td><td>Cell F</td>
</tr>
</table>

But what if you want your table to look like the following?

Heading A
Heading B
Heading C

Cell A & D
Cell B
Cell C

Cell E
Cell F

Heading AHeading BHeading C
Cell A & DCell BCell C
Cell ECell F


Here is the HTML code:

<table border=2>
<tr>
<th>Heading A</th><th>Heading B</th><th>Heading C</th>
</tr>
<tr>
<td rowspan=2>Cell A & D</td><td>Cell B</td><td>Cell C</td>
</tr>
<tr>
<td>Cell E</td><td>Cell F</td>
</tr>
</table>

Notice how the rowspan=2 attribute was added. This allows that cell to span two rows. If you want a cell to span more than one column then use the colspan=n attribute.

Also, you may wish to use the ALIGN and VALIGN attributes to align the contents of cells.

If you wish to change the horizontal alignment of the contents of a certain cell, add ALIGN=LEFT, ALIGN=CENTER, or ALIGN=RIGHT to the opening <td> tag.

If you wish to change the vertical alignment of the contents of a cell, use the VALIGN=TOP, VALIGN=MIDDLE, or VALIGN=BOTTOM attributes. You may also want to try out the WIDTH=n% attribute, to change the width of a table or a cell.

Here is an example of ALIGN attributes within a table...

Left Alignment
Center Alignment
Right Alignment

Left Alignment Center Alignment Right Alignment

Here is the HTML code:

Left AlignmentCenter AlignmentRight Alignment




Assignment #6


Create a table spreads across 100% of your page. Have the table border equal 4. Have 4 rows and 4 cols. Have 4 <th> tags. Write in them: NAME, LASTNAME, LIKES, DISLIKES. In the other 3 columns write the answers to the <th> tags.

Have Fun!!!

Click Here for the answer.


View The Basics of HTML Discussion

Page:  1 2 3 4 5 6 7 8 9 Next Page: Frames


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.