【问题标题】:Center div inside div (I know, its not working...)div 中的中心 div (我知道,它不工作......)
【发布时间】:2011-05-20 13:46:09
【问题描述】:

为什么这不起作用?它水平对齐正确,但在 Opera 中不是垂直对齐。在 IE 中它根本不起作用。

http://img834.imageshack.us/img834/340/86238198.png

#footer
{
    position: absolute;
    top: 905px;
    width: 100%;
    min-width: 800px;
    height: 95px;
    margin: 0px;
    background-image: url('footerbg.png');
}

#center
{
    position: relative;
    width: 20%;
    height: 70%;
    margin: auto;

    background-color: red;
}

【问题讨论】:

  • 你在使用文档类型吗?
  • 天哪。我从 HTML 4.01 Transitional 更改为 strict 并且它现在可以工作了...任何解释为什么它可以工作?

标签: html margin center


【解决方案1】:

在过渡(怪癖模式)中,IE 保持其旧版浏览器的行为,以免破坏在 IE 5 中构建为正常的现有网站。因此,在 IE 6 及更高版本中,如果您未定义一个 Strict doctype,那么它将诉诸其不尊重 margin:auto 的旧错误行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-26
    • 2018-07-03
    • 2017-12-11
    • 1970-01-01
    • 2018-03-30
    • 2013-07-15
    • 2012-01-27
    • 1970-01-01
    相关资源
    最近更新 更多