CSS way to horizontally align table

前端 未结 10 1169
礼貌的吻别
礼貌的吻别 2020-11-30 18:46

I want to show a table of fixed width at the center of browser window. Now I use

But Visual S

10条回答
  •  死守一世寂寞
    2020-11-30 19:40

    Simple. IE6 and above will happily center your table with "margin: 0 auto;" if only the page renders in "standards" mode. To make this happen you need a valid doctype declaration, such as

    
    

    or

    
    

    True, IE5.5 and below will still refuse to center the table but perhaps you can live with that, especially if the page is still functional with the table left aligned. I think by now users of IE5.5 and below are fairly used to some odd looking websites - but you still need to ensure that those visual glitches don't render your site unusable.

    Happy coding!

    EDIT: Sorry, I should perhaps point out that you do not have to have a "strict" doctype to get IE6 and up into "standards" rendering mode. I realised it might seem that way from the doctype examples I posted above. For example, this doctype declaration will of course work equally:

    
    

提交回复
热议问题