Professional Documents
Culture Documents
ICT1-Lesson Guide 15
ICT1-Lesson Guide 15
Grade 7 - ICT 1
Time : 3 hours/week
Introduction
Objectives
Lesson Proper
UNDERSTANDING TABLES
Creating tables in HTML is like piling together blocks or tiles, like the ones in your
bathroom. You start with a row and add the columns for that row. The main
difference is that you build from the top.
It is a good practice to plan your tables first before you start coding them in
HTML. You can do this on paper so you would know how many columns and rows you
would need and if some cells or headers need to span several rows and columns.
Arranging the Tags
The <table> tag is used to indicate the start of the table. This tag can have
border, height, and width as attributes. The <tr> tag indicates the start of a row in the
table and inside these tags you use the <td> tag to add the content in the cell. The
<th> tag is a special tag used for indicating the headers of the columns of the table.
All these tags have corresponding closing tags to indicate the end of the effect of each
tag.
For you to understand how these tags are arranged in your HTML code, study
the structure of a sample table below. The table has 3 rows and 3 columns, with the
first row used as a header.
This is how you build a table in HTML. The three steps needed are: (1) starting
the table; (2) starting the row; and (3) adding the content for each cell.
Putting Caption
A caption tells your readers what your table contains. To indicate a caption, you
must make sure that the <caption> </caption> tag pair is inside the <table> </table>
tag pair. Captions, by default, are placed at the top of the table. No matter where you
place a text with the <caption> tag, it will always be displayed at the top of the table,
unless you explicitly define its vertical alignment.
The sample HTML code below is an example of not explicitly defining the caption
alignment.
<html>
<body>
<table border>
<tr>
<td> This is col 1 of row 1 </td>
<td> This is col 2 of row 1 </td>
</tr>
<caption> This is the caption defined using the CAPTION tag
pair </caption>
</table>
</body>
</html>
To explicitly define a caption’s alignment, you can define it using the ALIGN
attribute of the <caption> tag. To put the caption at the bottom of the table, you add
BOTTOM to the ALIGN attribute as shown in the HTML code below.
<html>
<body>
<table border>
<tr>
<td> This is col 1 of row 1 </td>
<td> This is col 2 of row 1 </td>
</tr>
</table>
</body>
</html>
Using the ALIGN attribute of the <caption> tag
Defining Rows
In defining the structure of a table, you define it in this manner: Define the
rows first. The syntax for this is:
<tr>
Row content
</tr>
where the row content contains the columns and contents of the row.
Defining Cells
Cells are placed inside every row. Whenever a cell is defined column or columns
are implicitly defined. If a cell contains a heading, you use the table header <th>
</th> tag pair. Contents placed inside <th> tags are displayed in bold in most
browsers. If a cell contains data, you use the table data <td> </td> tag pair.
Contents placed inside <td> tags are displayed in normal text.
Spanning Cells
To define the number of rows a cell will span, use the ROWSPAN attribute of
the <td> tag.
To define the number of columns a cell will span, use the COLSPAN attribute
of the <td> tag
The sample HTML code below is an application on defining the table structure.
<html>
<body>
<table border>
<caption> Flower Prices </caption>
<tr>
<th> </th>
<th> 2-4 pcs </th>
<th> 5-8 pcs </th>
<th> 9-10 pcs </th>
<th> 12 or more </th>
</tr>
<tr>
<td> Rose </td>
<td rowspan=2> @45.00 </td>
<td> @40.00 </td>
<td colspan=2> @35.00 </td>
</tr>
<tr>
<td> Tulip </td>
<td> @42.00 </td>
<td> @36.00 </td>
<td> @32.00 </td>
</tr>
</table>
</body>
</html>
Even though rows and cells have already been defined, they can still be modified
to suit your taste. The attributes of a table that can be modified are the table borders,
the spacing between cells, the space between the table border and the cell border, the
alignment of cell contents, the space between the cell border and the content, and the
width and height of the cells and the entire table.
To change the width of the outside border (the border around the table), you
simply add a value to the BORDER attribute to indicate the thickness of the border in
pixels. The syntax to do is:
<table border=4>
<tr>
<th> This uses border = 4
</th>
</tr>
</table>
<br>
<table border=8>
<tr>
To change the spacing between cells, set the attribute CELLSPACING of the
<table> tag to the spacing you desire in pixels.
To change the alignment of the contents in all the cells in a row, use the ALIGN
attribute of the <TR> tag. The syntax for this is:
where alignment is either CENTER, RIGHT, or LEFT. The default alignment is RIGHT.
Below is a sample code on changing content alignment:
<html>
<body>
<table border>
<tr align=right>
<td> The content here is right-aligned </td>
<td> The content here is right-aligned </td>
</tr>
<tr align=left>
<td> Look at this; the content is left-aligned </td>
<td> Look at this; the content is left-aligned </td>
</tr>
<tr align=center>
<td> This is centered </td>
<td> This is centered </td>
</tr>
</table>
</body>
</html>
To change the alignment of the contents of individual cells, use the ALIGN
attribute of the <td> or <th> tag. The syntax for this is:
where alignment is either CENTER, RIGHT, or LEFT. The default alignment is RIGHT.
Below is the sample code in html:
<html>
<body>
<table border>
<tr>
<th align=right> The header is right-aligned </th>
<th align=left> Look at this header; it is left-aligned </th>
</tr>
<tr>
<td align=center> The content is center-aligned </td>
<td align=center> This content is also center-aligned </td>
</tr>
</table>
</body>
</html>
Sometimes you do not want to increase the width of the cell border. Instead,
you want to modify the amount of space present around the content of each cell (this
method is called cell padding). You can do so by indicating how many spaces in pixels
you want using the CELLPADDING attribute of the <table> tag. The syntax to do this
is:
<table border cellpadding = n>
Below is the sample code:
<html>
<body>
</body>
</html>
If you want the table to be displayed using your own defined width and height,
you can do so using the WIDTH and HEIGHT attributes of the <table> tag. The syntax
to do this is:
where height and width are values in pixels or percent depending on the window size.
<html>
<body>
</body>
</html>
Below is the output on the browser:
To change the height and width of the cell, you use the height and width
attributes of either the <td> tag or the <th> tag. The syntax to do this is:
<html>
<body>
<table border>
<tr>
<th height=250 width=10%> This header uses a 250 pixel height
and 10% of the screen width </th>
<td> This cell is affected by the header height and width since
it belongs to the same table </td>
</tr>
</table>
<br>
<table border>
<tr>
<th> This header is affected by the other cell since it belongs
to the same table </th>
<td height=100 width=210> This is 100 pixels in height and 210
pixels in width </td>
</tr>
</table>
</body>
</html>
Activity 14
Write the complete html code in a 1 whole sheet of paper that outputs the
multiplication table. The sample output is found on page 255 of your
textbook.
Note: You can use extra sheets, if one sheet is not enough. Do not forget to
write your name, your section and the activity number. Submit the said
activity on February 14, 2022.
References