HTML04: Tables
the tag for define a table in a page is <table>. A table consist of row and columns. As you may know, row is the horizontal line of records, and columns are the vertical ones. Each row has contains column cells. In a table first we must create a table, and inside these table we create column cells.
To define row in a table<tr> and to specify the data in each row <td> tag is ised. Also <th> is used to heading of the column
for example:
this will produce following table:
To merge cell of rows of same column, use rowspan attribute. the value given to the rowspan is number of cells to merge.
To define row in a table<tr> and to specify the data in each row <td> tag is ised. Also <th> is used to heading of the column
for example:
<table>
<tr>
<th>Fruits</th>
<th>Quantity</th>
</tr>
<tr>
<td>Apples</td>
<td>3 box</td>
</tr>
<tr>
<td>Orange</td>
<td>2 box</td>
</tr>
<tr>
<td>Grapes</td>
<td>4 box</td>
</tr>
</table>
<tr>
<th>Fruits</th>
<th>Quantity</th>
</tr>
<tr>
<td>Apples</td>
<td>3 box</td>
</tr>
<tr>
<td>Orange</td>
<td>2 box</td>
</tr>
<tr>
<td>Grapes</td>
<td>4 box</td>
</tr>
</table>
this will produce following table:
Fruits | Quantity |
---|---|
Apples | 3 box |
Orange | 2 box |
Grapes | 4 box |
The output don't have border. To draw border include border attribute <table border = "1">, all the borders in table will be displayed
Fruits | Quantity |
---|---|
Apples | 3 box |
Orange | 2 box |
Grapes | 4 box |
To merge cell of rows of same column, use rowspan attribute. the value given to the rowspan is number of cells to merge.
<table border = "1">
<tr><td>Apples</td><td>3 box</td></tr> <tr><td rowspan="2">Orange</td><td>2 box</td></tr> <tr><td>4 box</td></tr> </table> |
|
||||||
To merge cells of column is same row. use colspan attribute. Example below merges 2 cell in same row. | |||||||
<table border = "1">
<tr><td>Apples</td><td>3 box</td></tr> <tr><td colspan = "2">Orange</td></tr> <tr><td>Grapes</td><td>4 box</td></tr> </table> |
|
||||||
Adding a caption to table, a <caption> tag is used to give a short description about the table. |
|||||||
<table border = "1">
<caption>Fruit stock</caption> <tr><td>Apples</td><td>3 box</td></tr> <tr><td rowspan="2">Orange</td><td>2 box</td></tr> <tr><td>4 box</td></tr> </table> |
|
Comments
Post a Comment