开发者

How do I text-align:center php echo text in Firefox?

I don't see this question answered anywhere else here.

Here's the code:

<div class="copyright">
<h2 class="copyright unselectable" onselectstart="return false">
&copy;&nbsp;2009&nbsp;-&nbsp;<?=date("Y") ?>&nbsp;<?开发者_StackOverflow=PROJECT_NAME?>
</h2>
</div>

It's aligning right in IE but not FF or Safari. It seems to not be taking into account the spacing for the echoed text?

Thanks!

Edit: Adding css that is there:

div.copyright h2.copyright{
  font-family:Verdana, Arial, Helvetica, sans-serif;
  font-size:13px;
  color:#000000;
  font-weight:bold;
  text-align:center;
}

Second Edit: Well I just hard coded the text with the same results...so it's not the echo issue like I though. I'll have to look deeper at this.


Just add a style attribute to H2:

<h2 class="copyright unselectable" onselectstart="return false" style="text-align:center">
&copy;&nbsp;2009&nbsp;-&nbsp;<?=date("Y") ?>&nbsp;<?=PROJECT_NAME?>
</h2>

Or better, add that property to your CSS rule for .copyright:

.copyright {
    text-align: center;
    /* … */
}


The code sample that you posted seems to be aligning correctly to the center in both Firefox and Safari (on a Mac). The correct CSS to use is text-align: center;. What is the HTML and the associated CSS surrounding that piece of code? There could be something else causing the text to not look centered.


OK. I fixed it-and the answer is too stupid to post here...

...haha The box above the copyright area was not centering right in ff and safari but was right in IE. :-D


You can try

div.copyright h2.copyright{
  font-family:Verdana, Arial, Helvetica, sans-serif;
  font-size:13px;
  color:#000000;
  margin:0 auto;
  font-weight:bold;
  text-align:center;
}


Try giving the h2 a width. If you're using a reset stylesheet it's default styling may have been over ridden. If the h2 isn't wider than it's text, then it will appear that the text isn't being centered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜