Lab 6 HTML Tables: Objectives
Lab 6 HTML Tables: Objectives
HTML Tables
Objectives:
An HTML table is defined with the <table> tag. Each table row is defined with the <tr>
tag. A table header is defined with the <th> tag. By default, table headings are bold and
centered. A table data/cell is defined with the <td> tag.
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Asma</td>
<td>Mohammad</td>
<td>33</td>
</tr>
<tr>
<td>Ahmad</td>
<td>Naji</td>
<td>46</td>
</tr>
</table>
Note: The <td> elements are the data containers of the table.
They can contain all sorts of HTML elements; text, images, lists, other tables, etc.
Tasks:
<html>
<head>
border-color : red;}
th { color : green;}
td { color : blue;}
</style>
</head>
<body>
</body>
</html>
border: solid ;
border-collapse: collapse;
//single line border border-
width: 3px; border-color :
red;} th { color : green;} td { color : blue;}
</style> </head>
3. Table Cell Padding and cell spacing
Cell padding specifies the space between the cell content and its
borders. The cellspacing attribute specifies the space, in pixels,
between cells.
……
</table>
Or try this
• bgcolor attribute allow you to give a color to the cell or to the row.
<tr bgcolor=”blue”>
<th bgcolor=”red” >
<table>
<caption>Student Marks</caption>
<tr>
<th bgcolor=”red” >Name</th>
<th bgcolor=”red” >Mark</th>
</tr>
<tr>
<td>Ali</td>
<td>30</td>
</tr>
</table>
5. align Attribute
The align attribute specifies the horizontal alignment of the content in a cell.
<table >
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td align="left">$100</td>
</tr>
<tr>
<td>February</td>
<td align="center">$80</td>
</tr> </table>
6. valign Attribute
Try this
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td valign="bottom">January</td>
<td valign="bottom">$100</td>
</tr>
</table>
7. rowspan and colspan Attributes
rowspan: This attribute specifies the number of rows a cell should merged.
colspan: This attribute specifies the number of columns a cell should merged.
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
<td rowspan="2">$50</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
Write code for each:
1. A table that has a cell with an image and text in its content.
The <iframe> tag specifies an inline frame. An inline frame is used to embed
another document within the current HTML document.
1. iframe Attributes
Task. Create 3 html files : mm.html , bb.html and cc.html , write the next code in each
one:
1. mm.html
2. bb.html
<p>Welcome</p>
<img src=……/>
3. cc.html
<h1> Hello with iframes</h1>
Hometask:
<body>
</tr>
<tr>
<td rowspan="3">M<br>o<br>n<br>d<br>a<br>y</td>
<td valign="top"><b>Breakfast</b></td>
</tr>
<tr>
<td valign="top"><b>Lunch</b></td>
<td>Tuna sandwich<br>Apple</td>
</tr>
<tr>
<td valign="top"><b>Dinner</b></td>
</tr>
</table>
</body>
</html>
Table 1.
Table2.