在我的网站上,我有一个固定页脚位置,我想把中心文本放入其中。 奇怪的是,无论我在做什么,文本都不会居中,它总是会离开。
<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;
}
我已经尝试将身体默认对齐取消,如您所见,但没有效果。 有人有想法吗?
答案 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;
}
答案 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%;
}
答案 4 :(得分:1)
这是因为文字位于div
的中心,但如果添加边框,则会看到div
与文字一样大。
只需在页脚中添加width:100%;
即可。