So far we have looked at how we format a Web page. We have not looked at how we may position things within a web page.
Tables provide an simple way to organise a web page.
The <TABLE> .....</TABLE>
tag defines a table environment.
Within the Table data is organised as a sequence of rows with <TR> .... </TR>
tag.
Data in each row can be defied as being:
<TH> .... </TH>
. Usually printed in larger emphasised font
<TD> .... </TD>
. The main elements of table can be any HTML tag or text.
Each table element (header or data) in a row is called a cell.
Therefore to create a simple table we can do:
<TABLE > <TR> <TH><BR></TH> <TH>Red</TH> <TH>Yellow</TH> <TH>Blue</TH> </TR> <TR> <TH>Red</TH> <TD>Red</TD> <TD>Orange</TD> <TD>Purple</TD> </TR> <TR> <TH>Yellow</TH> <TD>Orange</TD> <TD>Yellow</TD> <TD>Green</TD> </TR> <TR> <TH>Blue</TH> <TD>Purple</TD> <TD>Green</TD> <TD>Blue</TD> </TR> </TABLE>
which looks like this:
|
Red | Yellow | Blue |
---|---|---|---|
Red | Red | Orange | Purple |
Yellow | Orange | Yellow | Green |
Blue | Purple | Green | Blue |
We might want to add things to a table:
The <CAPTION>...</CAPTION>
tag can be used to supply this.
<TABLE BORDER>
to give this effect.
So to return to the above example and give a Caption and a Border to the Table we can do:
<TABLE BORDER> <CAPTION><B>Table 1.1:</B> HTML Table with border and caption</CAPTION> <TR> <TH><BR></TH> <TH>Red</TH> <TH>Yellow</TH> <TH>Blue</TH> </TR> <TR> <TH>Red</TH> <TD>Red</TD> <TD>Orange</TD> <TD>Purple</TD> </TR> <TR> <TH>Yellow</TH> <TD>Orange</TD> <TD>Yellow</TD> <TD>Green</TD> </TR> <TR> <TH>Blue</TH> <TD>Purple</TD> <TD>Green</TD> <TD>Blue</TD> </TR> </TABLE>
which looks like this:
|
Red | Yellow | Blue |
---|---|---|---|
Red | Red | Orange | Purple |
Yellow | Orange | Yellow | Green |
Blue | Purple | Green | Blue |
Table Elements can be aligned horizontally and vertically by setting the respective ALIGN or VALIGN
attributes of the TD or TH tags:
Horizontal Alignment | ||
---|---|---|
Left |
Center |
Right |
Vertical Alignment | ||
Top
|
Center |
Bottom |
The HTML to produce this is:
<TABLE BORDER> <CAPTION>Alignment Options </CAPTION> <TR ALIGN=CENTER> <TH COLSPAN=3>Horizontal Alignment</TH> </TR> <TR> <TD ALIGN=LEFT> <BR> Left <BR> </TD> <TD ALIGN=Center> <BR> Center <BR> </TD> <TD ALIGN=RIGHT> <BR> Right <BR> </TD> </TR> <TR ALIGN=CENTER> <TH COLSPAN=3>Vertical Alignment</TH> </TR> <TR ALIGN=CENTER> <TD VALIGN=TOP> Top<BR> <BR> </TD> <TD VALIGN=MIDDLE>Center</TD> <TD VALIGN=BOTTOM> <BR> <BR> Bottom </TD> </TR> </TABLE>
Further information on tables may be found at: