文本对齐中心不起作用

时间:2013-01-04 19:00:12

标签: html css alignment

在我的网站上,我有一个固定页脚位置,我想把中心文本放入其中。 奇怪的是,无论我在做什么,文本都不会居中,它总是会离开。

<div id="footer">  
Copyright 2013 © LolStreamGallery - <a href="TermsofUse.html">Terms of Use</a>
</div>

CSS:

#footer {
    text-align:center;  
    position:fixed;
    bottom:0px;
    height:30px;
    background-color:#ededed;
    font-family: "Myriad Pro";
    font-size:14px;
}

也许你也想知道身体的CSS:

body {
    background-color:#ededed;
    /*text-align:left;*/
    margin:0;
    padding:0px; 
}

我已经尝试将身体默认对齐取消,如您所见,但没有效果。 有人有想法吗?

5 个答案:

答案 0 :(得分:5)

将其更改为:

#footer {
    text-align:center;  
    position:fixed;
    bottom:0px;
    height:30px;
    background-color:#ededed;
    font-family: "Myriad Pro";
    font-size:14px;
    width:100%; // added
}

<强> jsFiddle Live Demo

答案 1 :(得分:2)

你的页脚需要伸展到底部。为您的#footer样式元素添加宽度:100%。

#footer {
    text-align:center;  
    position:fixed;
    bottom:0px;
    height:30px;
    width:100%;
    background-color:#ededed;
    font-family: "Myriad Pro";
    font-size:14px;
}

http://jsfiddle.net/4zqbX/

答案 2 :(得分:2)

#footer设置为position: fixed时,它不再具有宽度。从技术上讲,#footer的内容仍然位于#footer内,但#footer从其内容的宽度中获取宽度。因此,您必须摆脱position: fixed或给#footer宽度。如果您将width: 100%添加到#footer,它应该有效。

答案 3 :(得分:1)

也许您需要为#footer

添加宽度
#footer {
    text-align:center;  
    position:fixed;
    bottom:0px;
    height:30px;
    background-color:#ededed;
    font-family: "Myriad Pro";
    font-size:14px;
    /*New*/
    width:100%;
}​

测试:http://jsfiddle.net/h6crw/1/

答案 4 :(得分:1)

这是因为文字位于div的中心,但如果添加边框,则会看到div与文字一样大。

只需在页脚中添加width:100%;即可。