Center a table in internet explorer

2019-07-31 19:21发布

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.

4条回答
男人必须洒脱
2楼-- · 2019-07-31 19:27

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

查看更多
家丑人穷心不美
3楼-- · 2019-07-31 19:34

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

查看更多
甜甜的少女心
4楼-- · 2019-07-31 19:46

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

查看更多
该账号已被封号
5楼-- · 2019-07-31 19:48

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">
查看更多
登录 后发表回答