简体   繁体   English

文字对齐中心不起作用

[英]Text align center wont work

On my website i have a position fixed footer, where i want to put centered text into. 在我的网站上,我有一个固定的页脚位置,我想在其中放置居中的文本。 The strange thing is that, whatever im doing the text wont be centered, its always left instead. 奇怪的是,无论我在做什么文本,都不会居中,而是始终留在原处。

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

CSS: CSS:

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

Maybe you wann know the CSS of the Body also: 也许您还想了解身体的CSS:

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

I have already tried to outcomment the body default align as you can see, but had no effect. 如您所见,我已经尝试过取消默认的正文对齐方式,但是没有任何效果。 Anybody a idea? 有人有主意吗?

Change it to this: 更改为此:

#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 jsFiddle现场演示

Your footer needs to stretch across the bottom. 您的页脚需要在底部延伸。 Add a width:100% to your #footer style element. 为您的#footer样式元素添加width: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/ http://jsfiddle.net/4zqbX/

When you set #footer to position: fixed , it doesn't have a width anymore. #footer设置为position: fixed ,它不再具有宽度。 So technically, the content of #footer is still centered within #footer , but #footer takes it's width from the width of its content. 因此从技术上讲,内容#footer内仍集中#footer ,但#footer需要这是从它的内容的宽度宽。 So, you have to either get rid of position: fixed or give #footer a width. 因此,您必须摆脱position: fixed或给#footer一个宽度。 If you add width: 100% to #footer it should work. 如果您添加width: 100% #footer width: 100% ,则应该可以使用。

Maybe you need add a width to your #footer 也许您需要在#footer中添加宽度

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

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

It is because the text is in the center of the div , but if add a border, you then see the div is just as big as the text. 这是因为文本位于div的中心,但是如果添加边框,则可以看到div与文本一样大。

Just add a width:100%; 只需添加width:100%; to the footer and your done. 到页脚,然后完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM