To center a table, set left and right margin to auto.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td { border: 1px solid black;
}
table.center { margin-left: auto; margin-right: auto;
}
</style>
</head>
<body>
<h1>Center a Table</h1>
<p>To center a table, set left and right margin to auto:</p>
<table class="center"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr>
</table>
</body>
</html>
Type
: |
html |
Category
: |
Web Tutorial |
Sub Category
: |
HTML Tag |
Uploaded by
: |
Admin |