user1471980
user1471980

Reputation: 10626

how do you center table using css

I have a table in my html that I would like to center on my page. I have the following code. I is perfectly find in ie but not in chrome. Am I doing something wrong?

<table align="center">
  <tr>
    <td>
      <div class="zoom_controls"> </div>
            </td>
   </tr>
</table>

Upvotes: 1

Views: 4675

Answers (3)

hosay
hosay

Reputation: 1

For me what worked is: margin: auto; display: inline-block;

Tables

Upvotes: -1

BlueCacti
BlueCacti

Reputation: 10820

Give the table a fixed width, if possible.
Give the table a top- and bottom-margin of 0 (or other if you want to) and a left- and right-margin of auto.

This works with every kind of element with a known width.
You can also use a variable width (em / %).

EDIT: seems like other were typing the same solution as me.

Upvotes: 0

j08691
j08691

Reputation: 207901

The align="center" syntax was deprecated a long time ago. Add margin:0 auto to your table:

table {
    margin:0 auto;
}

jsFiddle example (border added for visibility)

Upvotes: 5

Related Questions