Saturday, February 7, 2015

Tables in html

Tables could often cause problem to newbies and it could be very hard to understand and learn them.

To create a table we use tag <table>. In that tag there are tags <tr> (row) and <td> (cell) in HTML table. Here is an example of one table with 2 rows and 2 columns:
<table border="1">
<tr>
<td>First row and first column</td>
<td>First row and second column</td>
</tr>
<tr>
<td> Second row and first column</td>
<td> Second row and second column</td>
</tr>
</table>

Tables in html


In this way if we have one row in first cell and in second row there are two cells.
Here is an example:
<table border="1">
<tr>
<td rowspan="2">One row</td>
<td>First row</td>
</tr>
<tr>
<td>Second row</td>
</tr>
</table>


Rowspan numbered 2 means that there are two rows in one cell.  When you have two rows and one cell in one row and two cells in second row then you use colspan tag. Here is an example:

<table border="1">
<tr>
<td colspan="2">First row</td>
</tr>
<tr>
<td>First cell</td>
<td>Second cell</td>
</tr>
</table>





Cellspacing
You should use cellspacing for spacing between borders of tables. Look at this example:

<table border="1" cellspacing="6">
<tr>
<td colspan="2">First row</td>
</tr>
<tr>
<td>First cell</td>
<td>Second cell</td>
</tr>
</table>





Cellpadding
Cellpadding is used for spacing between text and borders of tables. Look at this example:

<table border="1" cellpadding="15">
<tr>
<td colspan="2"> First row</td>
</tr>
<tr>
<td>First cell</td>
<td>Second cell</td>
</tr>

</table>

No comments:

Post a Comment