0

What is the easiest way to center a whole table in the middle of a page with HTML?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

1

Use the following CSS:

table {
    margin: 0 auto;
}
danmullen
  • 2,556
  • 3
  • 20
  • 28
0

You cannot do it only with HTML.

<center> is only element that can do it, but is not preferred and is deprecated.

So you can use CSS for this. just put the parent element's position to be relative and set horizontal margins of this element to be auto.

example :

<div id="parent">
    <table>
        ....
    </table>
</div>

#parent {
    position: relative;
}
table {
    margin: 0px auto;
}
afzalex
  • 8,598
  • 2
  • 34
  • 61