页脚不响应中心命令
我正在制作一个非常简单的网站,但我的页脚有一个问题:它没有居中。我已经完成了所有的 margin-left:auto;和正确的事情,问题仍然存在于 Chrome 和 Firefox 中。代码:
#footer {
position: fixed;
z-index:10;
margin-left: auto;
margin-right: auto;
width: 1000px;
height:35px;
bottom:0px;
background-color:#363636;
/* Style info that has nothing to do with the problem below this line */
box-shadow: 1px -2px 6px rgba(0, 0, 0, 0.5);
-webkit-box-shadow:1px -2px 6px rgba(0, 0, 0, 0.5);
-moz-box-shadow:1px -2px 6px rgba(0, 0, 0, 0.5);
border-top-left-radius: 10px;
-moz-border-top-left-radius: 10px;
-webkit-border-top-left-radius: 10px;
border-top-right-radius: 10px;
-moz-border-top-right-radius: 10px;
-webkit-border-top-right-radius: 10px;
}
已经尝试输入“display:inline-block;”。 index.html 代码(ofc 仍在开发中,什么也没有): http://d.pr/btSa
提前致谢。
I'm making a very simple website and I've got a problem with my footer: it's not centering. I've done all the margin-left:auto; and right things, and the problem persists in Chrome and Firefox. The code:
#footer {
position: fixed;
z-index:10;
margin-left: auto;
margin-right: auto;
width: 1000px;
height:35px;
bottom:0px;
background-color:#363636;
/* Style info that has nothing to do with the problem below this line */
box-shadow: 1px -2px 6px rgba(0, 0, 0, 0.5);
-webkit-box-shadow:1px -2px 6px rgba(0, 0, 0, 0.5);
-moz-box-shadow:1px -2px 6px rgba(0, 0, 0, 0.5);
border-top-left-radius: 10px;
-moz-border-top-left-radius: 10px;
-webkit-border-top-left-radius: 10px;
border-top-right-radius: 10px;
-moz-border-top-right-radius: 10px;
-webkit-border-top-right-radius: 10px;
}
Already tried typing in "display:inline-block;".
The index.html code (ofc it's still in-dev, has nothing): http://d.pr/btSa
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
页脚未以边距居中的原因是由于
postion:fixed
。删除它,它将遵守您的margin
auto
的规则。如果您需要
修复
,请更新您的CSS,如下所示:注意添加
bottom:0;
,left:50%;
并更新margin
属性。The reason your footer is not centering with margin is because of the
postion:fixed
. Remove that and it will obey yourmargin
auto
's.If you need it to be
fixed
, update your css to look like this:note adding the
bottom:0;
,left:50%;
and updating themargin
properties.我认为你有一个问题:
位置:固定
尝试不使用它。如果您希望它粘在底部,请尝试使用其他位置(绝对位置等)。尝试使用 left: auto 和 right: auto 代替 margin: auto。因为在固定头寸上,我相信利润并不重要。
如果您坚持这样做,请尝试将页脚设置为 100% 宽度,将其固定在您想要的位置,然后将内容放入固定页脚内的包装中,并为其指定边距:0 auto。它将在页脚内居中。
I think you have a problem with the:
position: fixed
Try without it. If you want it stuck to the bottom try with other positions (absolute and etc). Try instead of with margin then to use left: auto and right: auto. since on fixed position i believe margins don't matter.
If you insist on it, try putting the footer as 100% width, make it fixed position and wherever you want it, then put the content in a wrapper inside the fixed footer and give that a margin: 0 auto. it will center inside the footer.
尝试在表格中使用页脚并将 td 对齐设置为居中
Try to use your footer in a table and set the alignment of td to center