水平居中页脚div

3

http://pixphoriad.haneuri.net/index2.php

顶部的div头部居中,但是页脚内容却没有居中。以下是页脚的css代码:

div#footer {
    background-color: #000;
    color: #fff;
    position:relative;
    height:350px;
    clear: both;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    width: 100%;
}
3个回答

2
将这些规则应用于center标签...
overflow: auto;
display: inline-block;

顺便说一下,center标签已经过时了,直到现在我才第一次看到它。但是不管怎样...

我喜欢整个网站...它展示了热情。


申请使用中心标签?虽然我同意,在footer.php中只有它被标记了,但是在那里它什么也没做,因为它不是我的CSS文件的一部分,而是自己的标签。它需要吗? - Kristin
你可以创建一个<div class='center'>,然后在CSS文件中加入.center { ...rules above ... }。Center标签将包含全部页脚内容。 - Muhammad Umer
@Kristin 如果这个答案是你最终采用的,请不要忘记将其标记为已接受的答案(点击左侧的灰色复选标记)。谢谢! - Maximillian Laumeister

2

定义你想要的 宽度 并像这样给出 margin

div#footer {
      width: 500px;
      margin: 0 auto; /* or `10px auto` to add margin top and bottom */
      text-align: center; /* align text center aligned*/
}

1
我建议您将以下行添加到您的

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接