Tables

Computer Education, Training & Tutorial Resources - ComputerEducationWorld.com
Home » Free Computer Training and Courses » HTML for Beginners »

Table is a matrix like object that holds other objects such as text, images, buttons and etc.
Even if you don’t see them they are present in all professional web pages. Hidden tables hold graphic images and text in their places in these pages.
Drawing a table
To draw a table we will use <TABLE> tag. We will need two other related tags to make table rows and columns. These are <TR> and <TD> tags. <TR> tag is used to create a row in table. Data that will fit in a row will be enclosed in <TR> </TR> tags. Following example produces a table with two rows. We will need <TD> tag to create columns in
each row.

<TABLE>
<TR>
<TD>First Row</TD>
</TR>
<TR>
<TD>Second Row</TD>
</TR>
</TABLE>

If you browse this code in a browser you may surprise. You will not see any table but two lines of code. In fact table is there but you cannot see it.  <TABLE> Tag will not make table borders. You must use a parameter to add borders to the table.
You can specify a border width for a table by adding a border parameter to <TABLE> tag.

<TABLE BORDER=1>
<TR>
<TD>First Row</TD>
</TR>
<TR>
<TD>Second Row</TD>
</TR>
</TABLE>

As you may guess default border size is 0. When we do not specify sizes for a table it will be in a size that it needs to be able to fit text or any other object that it will hold.

Specifying table sizes
You can specify width for a table both in percents of page width and in pixels.

Example:
<HTML>
<HEAD>
<TITLE>Example</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=50% BORDER=1>
<TR>
<TD>Cell Row1 Col1</TD>
<TD>Cell Row1 Col2</TD>
</TR>
<TR>
<TD>Cell Row2 Col1</TD>
<TD>Cell Row2 Col2</TD>
</TR>
</TABLE>
</BODY>
</HTML>

If you want you can determine table width in pixels.

<TABLE WIDTH=250 BORDER=1>
<TR>
<TD>Cell Row1 Col1</TD>
<TD>Cell Row1 Col2</TD>
</TR>
<TR>
<TD>Cell Row2 Col1</TD>
<TD>Cell Row2 Col2</TD>
</TR>
</TABLE>

You can specify table height too. In this way you can determine height and width of table. Width and height of table will be divided between cells in rows and columns so if table width is 100 and there are 2 columns then width of each cell will be 50.

Just pay attention to this important point that if you put a lot of text in a cell of a table it will be expanded to fit the text in it.
Text alignment in table cells
By default text entered in a cell will appear at the left side of the cell. You can add either of these options to <TD> tag to specify horizontal alignment of text.

<TD ALIGN=CENTER> or
<TD ALIGN=RIGHT> or
<TD ALIGN=LEFT>

As we saw, left alignment is default for cells.

You can also determine vertical alignment of text in a cell by adding VALIGN option to <TD> tag. There are three values for VALIGN option : TOP, BOTTOM and MIDDLE. MIDDLE is default value if you do not use this parameter.

Example:
<HTML>
<HEAD>
<TITLE>Example</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=50% HEIGHT=100 BORDER=3>
<TR>
<TD ALIGN=LEFT VALIGN=TOP>TOP LEFT</TD>
<TD ALIGN=RIGHT VALIGN=TOP>TOP RIGHT</TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=BOTTOM>BOTTOM LEFT</TD>
<TD ALIGN=RIGHT VALIGN=BOTTOM>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>


• • •
 



captcha PHP Script Free PHP captcha script free php
Website Design by WebWalas.com