|
Tables in HTMLWhether you realized it or not, you have already seen many examples of tables in HTML. Every one of my examples have been arranged on the screen by a table. Tables can be very confusing if you do not understand exactally what you are doing, but once you understand them, they become indispensable. You can think of an HTML table as you would any other table; a collection of columns and rows. Every table starts with a <TABLE> tag, and ends with </TABLE>. Further, each row begins with a <TR> tag, which stands for Table Row, and ends with </TR>. Inside these pair of tags, we define the actual information we want to be in the table by surrounding it with the pair of tags <TD> and </TD>, which stands for Table Definition. The basic syntax structure of a table is: <TABLE> <TR> <TD> . HTML Code . </TD> </TR> </TABLE>
As in earlier sections, HTML Code can be text, links, images, or any other HTML construct.
Example: Note: For this section I will offset the examples with horizontal rules in order to avoid confusion.
You may be thinking to yourself right now that you can't see anything different. This is because as a default, table borders are invisible. In order to see them, we must use the parameter BORDER on the <TABLE> tag. We can do our first example again to demonstrate this parameter. Example:
Adding more rows and columns is very easy. If you want another column, add another <TD> and </TD> pair between the <TR> and </TR> tag. This is demonstrated in the next example.
To add another row, we add another <TR> and </TR> pair inside <TABLE> and </TABLE>. The next example shows this.
You can see from these examples that the table will create the table and cell borders automatically. Each column will
be as wide as the widest element in it. Likewise, rows will be made the same height as the highest element in it.
This is all that you need to know in order to make basic tables.
You may decide that you want to label the top of each column in order to better identify what it is. To do this, you use the <TH> and </TH> tags. This pair of tags works in exactally the same way as the <TD> and </TD> tags, except that all text in the cell is made bold. You must also remember to put these headings into a new row.
The other features of tables come in the form parameters for the <TABLE> tag. They are BORDER, CELLSPACING,
CELLSPADDING, and WIDTH.
CELLSPACING changes the amount of space between the cell borders of the table. CELLPADDING puts space in between the items in the cell and its inside border. It is very easy to mix these two up. Especially when you are dealing with tables that do not have borders, and they will give you similar results. The next example will contrast their functions.
|