How can you center an entire table in Internet Explorer 7+?
I want to avoid on centering the <td>
element. I want to center the entire table with width:auto;
nearly 1050 pixels.
How can you center an entire table in Internet Explorer 7+?
I want to avoid on centering the <td>
element. I want to center the entire table with width:auto;
nearly 1050 pixels.
text-align: center;
on the body element should do it if the document is in quirks mode, otherwise the usual way of centering will also work even without a width on a table margin: 0 auto
added:
here's a link to a previous answer on the subject, covers both quirks and standards
CSS way to horizontally align table
You can use margin: 0 auto
to center.
This should be fine in IE7 although I don't have it to test with.
Working Demo
Make sure you have a Doctype that triggers standards mode, then set margin-left: auto; margin-right: auto;
on the table. Further reading: Centring using CSS
According to this blog post you should be able to use CSS, http://csssky.blogspot.com/2007/04/to-center-table-using-css-only.html
table { margin-left : auto; margin-right : auto; }
However, there seems to be an issue with IE 7 that they recommend adding the following to the beginning of the document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">