【问题标题】:centering with css doesn't work in internet explorer but does work in chrome以 css 为中心在 Internet Explorer 中不起作用,但在 chrome 中起作用
【发布时间】:2015-09-15 17:54:15
【问题描述】:

我正在尝试将一个 div 居中在一个具有左边距和右边距的 div 中。但它只适用于铬。我已经尝试过 !DOCTYPE html 但这不起作用。

HTML

    <div id="footer-links">
        <div id="footer-wrapper">
            <table id="table-links">        
            </table>
        </div>              
</div>

CSS

    #footer-links {
    width: 100%;
    height: auto;
    font-family: calibri;}

    #footer-wrapper{
    width: 1024px;
    position: relative;
    margin-left: auto;
    margin-right: auto;
}

这就是它在 IE 中的样子:http://puu.sh/kbYPO/36161cf305.png。 在 chrome 中就像这样:http://puu.sh/kbYPj/67d16bc661.png

【问题讨论】:

  • 使用魔法球 哦..哦,是的,我可以看到...呃..嗯..是的,这很烦人.. - 如果你没有得到提示: 没有任何代码,我们帮不了你。 :)
  • 我改了..抱歉我还没准备好。
  • 没关系,我现在看看
  • @ThijnLinders 请仅在问题完成后提交。 :) 早点按下“提交”按钮是没有用的:你不会更快地获得帮助,而且人们很快就会对不完整的问题投反对票。
  • 嗯感觉很奇怪.. 仍然不完整。你能指定你想要居中的 div 吗?

标签: html css google-chrome internet-explorer


【解决方案1】:

希望你能学到一些东西。

在被否决后更新 1.0

HTML

    <div id="footer">
        <p>Hello World</p>
    </div>

CSS

body {
    margin: 0;
    padding: 0;
    height: 100%;
}
html {
    height: 100%;
    margin: 0;
    padding: 0;
}

#footer {
    position: absolute;
    width: 100%;
    clear: both;
    bottom: 0;
    padding: 0;
    margin: 0;
    height: 30px; /* REMEMBER height = padding-bottom */
    background: #333;
}

#footer p{
    color: white;
    text-align: center;
    margin-top: 8px;
}

结果。

在 IE8 中测试

【讨论】:

  • 我没有对你投反对票,但是:为你的代码提供一个 jsFiddle 可能是个好主意,这样其他人就可以立即检查它是否有效。此外,“尝试使用它”可能意味着您不确定自己,这也可能导致投反对票。
  • @Jordumus 大声笑,因为提问的人没有提供足够的信息。而且我也不知道文本来自哪里。至少 text-align:center;应该可以工作并将宽度设置为 100%。
  • 社区在为您投票时并不关心这个问题,他们关心的是您的回答;)如果它不符合准则,它将被否决。 :)
猜你喜欢
  • 2020-09-16
  • 2013-11-18
  • 1970-01-01
  • 2014-10-17
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多