Search code examples
htmlcsshtml-tablealignment

Centering a table in Firefox


I've got a small table on one of my pages and I'd like it centered so have coded <table cellpadding="0" cellspacing="0" align="center">which works fine in IE but the table still left aligns in Firefox.

If i use text-align:center n align:-moz-centerits not working in IE

What do I need to change to get the table to center in Firefox? If I should use -moz-center how to make it work in IE?

I'm stuck here.


Solution

  • As Lekensteyn mentioned, here is some code to show it in action:

    <div style="margin: 0 auto; text-align:center;">
    <table border="1" style="width:200px;">
    <tr>
      <td>Hello</td>
      <td>How</td>
    </tr>
    <tr>
      <td>are</td>
      <td>you?</td>
    </tr>
    </table>
    </div>
    

    it should center itself based on the width & margin style definition.