This lesson assumes that you understand the basic tables presented in Lesson Eleven and are now ready to take a look at some more advanced table features.
You may have noticed in the table on my main home page
that I did not use the CAPTION tag. Instead, I placed the instructions
for the table in the first row which spanned across all the columns.
For example, here is a simplified version of the table on my home page.
I grouped the first four lessons together and
used a value of "3" for each of the BORDER, CELLSPACING and CELLPADDING
attributes.
| |||
| LESSON ONE Introducing HTML | LESSON TWO Getting started | LESSON THREE <BR>, <P>, <HR> and other basic tags | LESSON FOUR Emphasizing text and Heading tag |
Here are the lines that generated this part of the table (I double spaced the command lines for easier viewing):
<TABLE BORDER="3" CELLSPACING="3" CELLPADDING="3" WIDTH ="100%">
<TR>
<TD ALIGN="CENTER" COLSPAN="4"><H3> <BR>CHOOSE ANY LESSON</H3>
<TR>
<TD ALIGN="CENTER"><A HREF="lesson1.htm">LESSON ONE<BR>Introducing HTML</A>
<TD ALIGN="CENTER"><A HREF="lesson2.htm">LESSON TWO<BR>Getting started</A>
<TD ALIGN="CENTER"><A HREF="lesson3.htm">LESSON THREE<BR><BR>, <P>, <HR><BR> and other basic tags</A>
<TD ALIGN="CENTER"><A HREF="lesson4.htm">LESSON FOUR<BR>Emphasizing text<BR> and Heading tag</A>
</TABLE>
The line that generated the first row that spanned across all four columns is:
<TD ALIGN="CENTER" COLSPAN="4"><H3> <BR>CHOOSE ANY LESSON</H3>
Note the following points:
<TR ALIGN="CENTER">
| METALS AND THEIR REASONABLE CUTTING SPEEDS | ||
|---|---|---|
| MATERIAL | Starting Speed in Feet per Minute | |
| High-Speed Steel | Carbide | |
| Stainless Steel | 50 | 150 |
| Cast Iron | 74 | 225 |
| Brass | 300 | 800 |
| Copper | 300 | 1000 |
Here are the lines that make this table. You any wish to SWITCH to NOTEPAD and type it in, then save and load it into your browser to see if everything comes out the same. We will be making a change to this table in the next section.
<TABLE BORDER="5" CELLSPACING="0" CELLPADDING="3">
<TR>
<TH COLSPAN="3">METALS AND THEIR REASONABLE CUTTING SPEEDS
<TR>
<TH>MATERIAL
<TH COLSPAN="2">Starting Speed<BR>in Feet per Minute
<TR>
<TH>
<TH>High-Speed<BR>Steel
<TH>Carbide
<TR>
<TD>Stainless Steel
<TD ALIGN="CENTER">50
<TD ALIGN="CENTER">150
<TR>
<TD>Cast Iron
<TD ALIGN="CENTER">74
<TD ALIGN="CENTER">225
<TR>
<TD>Brass
<TD ALIGN="CENTER">300
<TD ALIGN="CENTER">800
<TR>
<TD>Copper
<TD ALIGN="CENTER">300
<TD ALIGN="CENTER">1000
</TABLE>
</BODY></HTML>
Now for a discussion:
ROWSPAN
Let's take the last example, and have the heading MATERIAL fill the
first two rows in the first column so that the empty cell is eliminated.
In other words, let's change the table to look like:
METALS AND THEIR REASONABLE CUTTING SPEEDS | ||
|---|---|---|
| MATERIAL | Starting Speed in Feet per Minute | |
| High-Speed Steel | Carbide | |
| Stainless Steel | 50 | 150 |
| Cast Iron | 74 | 225 |
| Brass | 300 | 800 |
| Copper | 300 | 1000 |
There are really only two changes that have to be made to have "MATERIAL" span two rows:
<TABLE BORDER="5" CELLSPACING="0" CELLPADDING="3">
<TR>
<TH COLSPAN="3"><BR>METALS AND THEIR REASONABLE CUTTING SPEEDS<BR><BR>
<TR>
<TH ROWSPAN="2">MATERIAL
<TH COLSPAN="2">Starting Speed<BR>in Feet per Minute
<TR>
<TH>High-Speed<BR>Steel
<TH>Carbide
<TR>
Note that "MATERIAL" spans row 2, column 1 and row 3, column 1. These two cells are now considered occupied. Thus the first <TH> for row 3 (High Speed Steel) is considered to be in the second column. Therefore "High-Speed Steel" in the third row was printed in the second column as the first column was occupied. So if a cell spans more than one row or column, just ignore the cell and move to the next available cell in the row.
Now it's your turn to make up a table. There is nothing like learning by doing.
Problem 1: Make up the HTML document that will give the following
table:
DRILL SPEEDS | |||||
|---|---|---|---|---|---|
| MATERIALS | DIAMETER IN INCHES | CUTTING SPEED | RPM | ||
| Feet | Metres | ||||
| 1. | Brass | 2.5 | 350 | 560 | |
| 2. | Cast iron | 4.5 | 69 | 201 | |
| 3. | Copper | 1 | 300 | 1200 | |
| 4. | Stainless Steel | 3.625 | 46 | 167 | |
Problem 2: Write the HTML document that gives the following calendar.
Use the value "3" for each of the attributes BORDER, CELLSPACING and
CELLPADDING.
| JULY | ||||||
|---|---|---|---|---|---|---|
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | ||
If you would like to see your web page or part of your web page separated into two sections by a vertical line (a side-line), you could set up it up as a one row, two column table. You could choose a table WIDTH of 100% and a table HEIGHT of any number of pixels that you desire. The width of the table can also be expressed in pixels. If your browser supports full color, the left side is colored yellow.
Here is an example:
| This side is colored yellow
Feel free to place anything on this side. This cell is 30% of the browser screen width. Note that the HEIGHT is in pixels (600) and not as a percent. | This side just shows plain text.
You can color it too if you want. This side is 70% of the width of the screen. Both sides are 600 pixels long. But you can change it to anything you want. Here is the BODY of the HTML document that gives this table. A brief explanation is given to the left. <TABLE BORDER="1" CELLSPACING="0" CELLPADDING="10" WIDTH="100%" HEIGHT="600"> |
Now if you do not want a border, just remove the TABLE attributes BORDER and CELLSPACING so the TABLE tag becomes:
<TABLE CELLPADDING="10" WIDTH="100%" HEIGHT="600">
Here is what you should see:
| This
side is colored yellow
Feel free to place anything on this side. This cell is 30% of the browser screen width. Note that the HEIGHT is in pixels (600) and not as a percent. | This side just shows plain text.
You can color it too if you want. This side is 70% of the width of the screen. Both sides are 600 pixels long. But you can change it to anything you want. Here is the BODY of the HTML document that gives this table. A brief explanation is given to the left. <TABLE CELLPADDING="10" WIDTH="100%" HEIGHT="600"> |
Here is another example of a side-line dividing the screen into two
two columns. I have removed the yellow background color but you could
experiment by leaving it in to see the effect. An explanation and the
BODY of this HTML document is given below the table.
This cell is 30% of the browser screen width. The vertical line is really an image
placed in this cell and aligned to the right side of the cell. | This is the right side of the table.
I could have placed the vertical line (the image) in this cell by aligning it to the left side of the cell. This line is 600 pixels in height (the same length as the table) and 2 pixels wide. |
As stated in the above "invisible" table, the line is only an image which I named "linevert.gif". I placed it in the first cell and aligned it to the right side of the cell. I just as easily could have placed it in the second cell and aligned it to the left side of the cell. Feel free to save this line and use it in your own web pages. As you can see below in the IMG statement, I defined the line to be 600 pixels long and 2 pixels wide. If you save this image, be sure to experiment with different lengths and widths.
Here is the BODY of the HTML document that gives rise to this table.
<TABLE CELLPADDING="10" WIDTH="100%" HEIGHT="600">
<TR VALIGN="TOP">
<TD WIDTH="30%"><IMG SRC="linevert.gif" ALIGN="RIGHT"
HEIGHT="600" WIDTH="2" ALT="">Feel free to place anything on
this side.
<P>This cell is 30% of the browser screen width.
<P>The vertical line is really an <STRONG>image</STRONG>
placed in this cell and aligned to the right side of the cell.<BR>
<TD WIDTH="70%">This is the right side of the table.
<P> I could have placed the vertical line (the image) in this cell
by aligning it to the left side of the cell.
<P> This line is 600 pixels in height (the same length as the table)
and 2 pixels wide.
</TABLE>
You learned in Lesson Eleven that the WIDTH can also be expressed in pixels instead of as a percent. Therefore, instead of WIDTH="30%" for the first cell, you could use, for example, WIDTH="200" representing 200 pixels. If the average screen width is 600 pixels, then 200 pixels represents one third of the width. I often see the first cell defined in pixels on other web pages. There is no need to define the width at all for the second cell as screen widths vary from browser to browser. As you learned in the last lesson, specifying a width in pixels will give an exact width which can't be changed (and you may want this to be the case). Specifying the width as a percent of the current screen will allow the table to be expanded or compressed to fit the viewer's browser screen. It would be a good learning experience to do some experimenting with the WIDTH attribute.
There is one more side-line option that you will find very
interesting and one that you may want to consider. To see this one,
along with an explanation, just click here.
Answer to Problem 1: Here is the BODY part of the HTML document. I numbered the first 13 lines so I can refer to them in the discussion given below the document.
Line 1: <TABLE BORDER="5" CELLSPACING="0" CELLPADDING="3">
Line 2: <TR>
Line 3: <TH COLSPAN="6"><BR>DRILL SPEEDS<BR><BR>
Line 4: <TR>
Line 5: <TH ROWSPAN="2">
Line 6: <TH ROWSPAN="2">MATERIALS
Line 7: <TH ROWSPAN="2">DIAMETER<BR>IN INCHES
Line 8: <TH COLSPAN="2">CUTTING SPEED
Line 9: <TH ROWSPAN="2">RPM
Line 10: <TR>
Line 11: <TH>Feet
Line 12: <TH>Metres
Line 13: <TR>
Answer to Problem 2:
The first row in the table contains the month "JULY" and this row spans all 7 columns. The blank cell in row 3 spans 2 columns (under "Sun" and "Mon") and to make it take on the appearance of the other cells, I printed the space character (&nbsp;) in it. Feel free to experiment with different designs of calendars. Here is the BODY of the HTML document that gives this calendar:
<H3 ALIGN="CENTER">
<P><TABLE BORDER="3" CELLSPACING="3" CELLPADDING="3">
<TR>
<TH COLSPAN="7">JULY
<TR>
<TH>Sun
<TH>Mon
<TH>Tue
<TH>Wed
<TH>Thu
<TH>Fri
<TH>Sat
<TR ALIGN="CENTER">
<TD COLSPAN="2">
<TD>1
<TD>2
<TD>3
<TD>4
<TD>5
<TR ALIGN="CENTER">
<TD>6
<TD>7
<TD>8
<TD>9
<TD>10
<TD>11
<TD>12
<TR ALIGN="CENTER">
<TD>13
<TD>14
<TD>15
<TD>16
<TD>17
<TD>18
<TD>19
<TR ALIGN="CENTER">
<TD>20
<TD>21
<TD>22
<TD>23
<TD>24
<TD>25
<TD>26
<TR ALIGN="CENTER">
<TD>27
<TD>28
<TD>29
<TD>30
<TD>31
<TD COLSPAN="2">
</TABLE></H3>