2-HTML Tables
2-HTML Tables
HTML Table
• The <table> tag begins the table, place what want inside and end the
table with the </table> tag. To begin adding contents to table, need the
<tr> and <td> tags.
• The <tr> stands for table row and the <td> stands for table data, which is
what will place after <table> tag. End a table, data section with the </td>
tag and each table row with the </tr> tag.
2
Example
<table>
<tr>
<td>
This is my table!
</td>
</tr>
</table>
3
Cont..
<body>
Hi!
<table border="2">
<tr>
<td>
This is my table!
</td>
</tr>
</table>
</body>
4
Example
<body>
Hi!
<table border="2">
<tr>
<td>This is cell 1</td>
<td>This is cell 2</td>
</tr>
</table>
</body>
5
Cont..
td
<body>
Hi! tr row 1, cell 1 row 1, cell 2
Fruit Percentage
Bananas 23%
Oranges 13%
Other 10%
8
Cell Padding and Spacing
• Setting the cellpadding attribute determines how much space will exist
between a table cell border and the elements contained within it, whereas
cellspacing determines how much space will exist between each table
cell
9
Cont..
<tr>
<td><b>Column 1</b> </td>
<td><b>Column 2</b> </td>
</tr>
<tr>
<td>Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
</tr>
<tr> <td>Row 2 Cell 1</td>
<td>Row 2 Cell 2</td>
</tr>
11
</table>
Table width & height
12
Cont..
<table border=“2” bordercolor=“red” width=“100%” height=“70%” >
<tr>
<td>
This table really long !
</tr>
</td>
</table>
13
align
• align=“left”
Aligns cell contents to the left
• align=“center”
Aligns cell contents to the center
• align=“right”
Aligns cell contents to the right
14
Cont..
<table width=“450” border=“2” cellspacing=“7”
cellpadding=“7”>
<tr>
<td align="center">
I’m in the center !
</td>
<td align="right">
I’m aligned to the right!
</td>
</tr>
</table> 15
valign
• Valign=“top”
Align contents to the top of the cell
• Valign=“middle”
Align contents halfway between the top and bottom of the cell
• Valign=“bottom”
Align contents to the bottom of the cell
16
Cont..
<table width=“550” border=“2” cellspacing=“7” cellpadding=“0”>
<tr>
</tr>
</table> 17
bgcolor
<table border=“5” bgcolor="red">
<tr>
<td>
Red Rules!
</td>
</tr>
</table>
18
Cont..
<table width="75" border=“2”>
<tr>
<td bgcolor="red">
Red
</td>
<td bgcolor="blue">
blue
</td>
</tr>
</table>
19
Cont..
<table width="200" border=“2”>
<tr bgcolor="red">
<td>Red</td>
<td>Red Again...</td>
</tr>
<tr bgcolor="blue">
<td>Blue</td>
<td>Blue Again... Again...</td>
</tr>
</table>
20
Rowspan = “ ”
21
Example 01
<table border="2">
<tr>
<td align="center">
Nice guy,Idn' he?
</td>
<tr>
<td align="center">
Met him at the shop
</td>
</tr>
</table> 22
Example 02
<table border="1" >
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td rowspan="2">d</td>
<td>e</td>
<td>f</td>
</tr>
<tr>
<td>g</td>
<td>h</td>
</tr>
23
</table>
Exercise
<table border="1" >
<tr>
<td rowspan ="3">m</td>
<td>h</td>
<td>y</td>
</tr>
<tr>
<td>p</td>
<td rowspan="2">e</td>
</tr>
<td>r</td>
</tr>
</table> 24
Colspan = “ ”
25
Example 01
<tr>
<td colspan="3" align="center"><b>Table header</b>
</tr>
<tr>
<td align="center">Table cell 1</td>
<td align="center">Table cell 2</td>
<td align="center">Table cell 3</td>
</tr>
</table>
26
Example 02
<table border="1">
<tr>
<td colspan="3">s</td>
</tr>
<tr>
<td>s</td>
<td>s</td>
<td>s</td>
</tr>
<tr>
<td colspan="2">s</td>
<td>s</td>
</tr>
</table> 27
Exercise
<table border="1" width="100">
<tr>
<td colspan="2">a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td rowspan="2">f</td>
<td rowspan="3">g</td>
</tr>
<tr>
<td>h</td>
<td>i</td>
</tr>
<tr>
<td colspan="2">j</td>
28
<td>k</td>
<tr title=“ ”>
<table border="1">
<tr title="You are looking at Row 1” bgcolor="silver">
<td>Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
</tr>
<tr title="You are looking at Row 2" bgcolor="aqua">
<td>Row 2 Cell 1</td>
<td>Row 2 Cell 2</td>
</tr>
</table>
Row 1 Cell 1 Row 1 Cell 2
30
31