HTML-2 (class notes)
HTML-2 (class notes)
2
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
<table>
// content of the table
</table>
Example :
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
Size of table
Example:
<body>
<table style width=90%>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Neha</td>
<td>18</td>
</tr>
<tr>
<td>Jiya</td>
<td>20</td>
</tr>
</table>
</body>
Size of column
Example:
<body>
<table style width=90%>
<tr>
<th>Name</th>
<th style="width:30%">Age</th>
</tr>
<tr>
<td>Neha</td>
<td>18</td>
</tr>
<tr>
<td>Jiya</td>
<td>20</td>
</tr>
</table>
</body>
</html>
Size of row
<body>
<table style width=90%>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr style="height:80px">
<td>Neha</td>
<td>18</td>
</tr>
<tr>
<td>Jiya</td>
<td>20</td>
</tr>
</table>
</body>
Table headers vertically
<table style width=90%>
<tr>
<th>Name</th>
<td>Neha</td>
<td>18</td>
</tr>
<tr>
<th>Age</th>
<td>Jiya</td>
<td>20</td>
</tr>
</table>
Text align in tables
<head>
<style>
table, tr, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th {
text-align: right;
}
</style>
</head>
COLSPAN AND ROWSPAN
Colspan: If you want a table cell to span multiple columns, you can use the colspan attribute.
Rowspan: If you want a table cell to span multiple rows, you can use the rowspan attribute.
Example of colspan:
<body>
<table style width=100%>
<tr>
<th colspan="2">Name and Age</th>
</tr>
<tr>
<td>Neha</td>
<td>18</td>
</tr>
<tr>
<td>Jiya</td>
<td>20</td>
</tr>
</table>
</body>
Example of rowspan:
<body>
<table style width=100%>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td rowspan="2">Neha , Riya</td>
<td>18</td>
</tr>
<tr>
<td>20</td>
</tr>
</table>
</body>
Cell padding
• Cell padding is the space between the cell edges and the cell content.
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 30px;
}
</style>
</head>
• Example:
To specify different padding for all fours sides of the cell content.
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding-top: 10px;
padding-bottom: 5px;
padding-left: 20px;
padding-right: 40px;
}
</style>
Cell Spacing
Cell spacing is the space between each cell.
<head>
<style>
table, th, td {
border: 1px solid black;
}
table {
border-spacing: 20px;
}
</style>