|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
01) WHAT IS A TABLE?First, let's begin by becoming familiar with a few terms associated with tables.A table is a rectangular arrangement of rows and columns. The data in a table is placed there in an organized manner.
02) WHY USE TABLES?There are several reasons for using tables.First, the lining up of text is made easier with tables. Second, text wraps inside each cell, meaning that if you have more than one line of text, it will automatically stay in that same cell. Third, tables are self-contained. You can edit and format the contents of a cell without disturbing other cells. Fourth, tables can also include images and links, not just text. And fifth, most of the text tags (<B>,<I>,<H1>, etc.) can be used inside of tables. Tables are a convenient way for displaying information in a very organized manner.
03) BUILDING A SIMPLE TABLEA table always begins and ends with <TABLE> and </TABLE>. If you want a border around your table, you would use <TABLE BORDER=n> instead of <TABLE>, where 'n' is equal to the number of pixels you'd like the width of the border set to. If you'd like your table to be invisible (not show any of the lines on the Web page), then set 'n' to 0. There are other tags that go within the table tag, but before we talk about those, let's look at the basic layout of a simple table. So, how do you build a table? First, you would determine how many rows and columns you want in the table. Second, add the first row. Third, divide that row up into however many columns you want. Fourth, put the data into each cell. You would repeat those four (4) things until you were finished with the table. The tag for adding a new table row is <TR> (TR stands for Table Row) and </TR> ends that row. Next, to divide that row up into columns, you would use the <TD> (TD stands for Table Data) and </TD> tags. Each <TD> represents one column cell.
Suppose you want a table that has two (2) columns and three (3) rows, with the
table border being three (3) pixels wide. How would you code this in HTML? ...
How would the above HTML code look on the Web page?
Like this:
In the above table, we wanted two (2) columns and three (3) rows. Notice that there are three
(3) <TR>s, with each beginning a new row. Note that inside of each <TR>, there are two
(2) <TD>s. This is your two (2) columns in the row. The text you want would be typed between the <TD> and </TD>.
Why would one want to put an image in a table? What if you wanted your Web page to have a paragraph with an image on each side? Try that without a table and you'll be pulling your hair out within 15 minutes. But, with a table, it's simple. You would create one
(1) <TR> with three (3) <TD>s (image, paragraph, image). Here's part of the code:
...
The first column of the above table would display firstpic.jpg, the second column would contain your paragraph, and the third column would display
secondpic.jpg.
The code for the table above is: <TABLE border="1" width="100%"> 04) USING HEADERS IN TABLESIf you have a table that includes quite a bit of statistics, data, or whatever, you will probably want to put headers at the top of it to help the reader understand the information in the table. The tags for headers within tables are <TH> and </TH> (abbreviation from Table Header). To define the headings of your table, (this will be always displayed on the first row), you would use this code:
...
Here's what the above table looks like:
05) USING CAPTIONS IN TABLESRemember what a caption is? It's a very short description that tells the reader what the table is all about. You might say it's the title of the table. Here's the tag for defining a caption:
<CAPTION ALIGN=where>Caption text goes here.</CAPTION>
The 'where' in that tag is either TOP or BOTTOM. If you use TOP, the caption appears above the table. If you use BOTTOM, the caption appears below it. Here's sample code of a caption located at the top of a table:
<TABLE BORDER=2> Here's what that table looks like:
So, what makes <TH> and <TD> different from one another? Text between <TH> and </TH> will always appear centered and bolded. Text between <TD> and </TD> won't (unless you tell it to).
You can certainly make a great-looking table with all of the information provided above. But, there are some 'EXTRA' things you can do to jazz it up some. Unless you specify otherwise, data entered into a table with <TD> will be left-aligned. Data entered into headers with <TH> will automatically be centered, unless you tell it otherwise. So, what are the other choices and what are their formats?
<TD ALIGN=where> In both of those cases, 'where' can be LEFT, CENTER, or RIGHT. There is also one more way to align data within a cell: Vertically. The vertical format uses VALIGN. <TD
VALIGN=where> In both of those cases, 'where' can be TOP, MIDDLE (the default), or BOTTOM of the cell. 07) SPANNING TEXT ACROSS MULTIPLE ROWS OR COLUMNSSo far, each bit of data entered has just been put into one cell. But, what if you have data that needs to take up more than one cell, either vertically, or horizontally? Such cells that take up more than one space in a column or row are said to span. This could come in very handy with headers or even graphics. Here is the tag for spanning columns:
<TD COLSPAN=n> Where the value of 'n' is the number of columns you want the cell to span across. Spanning multiple rows is similar, except that you substitute ROWSPAN for COLSPAN.
<TD ROWSPAN=n> Again, the value of 'n' is the number of rows you want the cell to span. Suppose you want to create a table that spans two (2) rows. This is the code: <TABLE BORDER=2>
Here are samples of tables, with the table/row/column/cell description inside each cell, using HTML code (for 5 tables) using the extensions and information given on this page: Table 1
Table 2
Table 3
Table 4
Table 5
The table values for each of the tables above is given inside of each individual table. Take a few minutes to look these tables over and compare the values with how they appear on the Web page.
HTML TUTORIAL
|