Reputation: 219
How can I center the table
within a div
using html?
I have placed my content within a div
tag and set the text-align
attribute to center
like the following.
text-align: center;
This has not worked.
Below is my html.
<html>
<body>
<div style="text-align:center">
<p>
text test
</p>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</div>
</body>
</html>
Upvotes: 8
Views: 59527
Reputation: 680
<div style="text-align:center">
<table style="display: inline-table;">
</table>
</div>
Upvotes: 3
Reputation: 344
<html>
<body>
<div style="text-align:center">
<p>
text test
</p>
<table border="1" style="margin: 0 auto;">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</div>
</body>
</html>
Upvotes: 1
Reputation: 4553
Edit the table tag like below
<table border="1" align="center">
and then check.
Upvotes: 1
Reputation: 319
you can put the style in the table
<table border="1" style="margin:0 auto;">
However I do suggest that you use a style sheet and not inline styles
Upvotes: 0
Reputation: 1878
Instead of <div style="text-align:center">
you could write <div style="width:600px;margin:0 auto">
Which gives you a div with the width of 600 pixels and centers the div in the parent element.
Upvotes: 0
Reputation: 2822
Give width to table, and set margin auto horizontally.
table {
width:500px;
margin: 10px auto;
}
Upvotes: 27
Reputation: 22619
Try the below
<table style="margin:0px auto; width:500px">
Upvotes: 7