2012-08-23 41 views
2

我正在将网站重新编写为HTML5,并且在对页脚中的内容进行居中处理时遇到了一些问题。使用html5将CSS中的页脚内容置于中心

我的页脚HTML是非常简单的

<footer> Copyright </footer> 

和CSS是

footer { 
    margin: auto; 
    height: 330px; 
    background-color: #1e2127; 
    color: #ffffff; 
} 

但内容不与页面的其余部分居中。

我错过了什么?

编辑:
我不想中心页脚中的文本,只页脚它的自我(所以它会随着页面的其余部分对齐),但我想在后台填写整个页面。

+0

5回答只需3分钟:o – Jack

回答

3

我假设你想要的页脚水平居中,在这种情况下margin: auto;需要指定宽度自动中心:

footer { 
    margin: auto; 
    width: 960px; 
    /* other styles */ 
} 
3

希望这是你想要的demo

footer { 
    margin: auto; 
    height: 330px; 
    background-color: #1e2127; 
    color: #ffffff; 
    text-align:center; //to align the text in center 
}​ 
+0

+1只是因为你是演示:D – Jack

+0

@杰克thanx赞赏:) – Uttara

+0

真正值得的答案,其快速准确,并与演示! – Jack

1

你是缺少text-align:center以使内容中心对齐。

1

集水木清华这样的:

<footer><span>Copyright<span></footer> 

和css:

footer { 
    margin: auto; 
    height: 330px; 
    width: 100%; 
    background-color: #1e2127; 
    color: #ffffff; 
} 

footer span { 
    display:block; 
    width: 50%; 
    margin: 0 auto; 
    text-align: center; 
} 
1
footer { 
    margin: 0 auto; 
    height: 330px; 
    background-color: #1e2127; 
    color: #ffffff; 
} 

保证金:如果父容器有一定的宽度 否则为0自动将工作,你可以尝试把text-align:center;

3

您尚未给出页脚宽度,这意味着它将默认到100%,文本左对齐。添加文本对齐:居中以文本居中,或者添加宽度以居中整个页脚。