English 中文(简体)
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;<?=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.

最佳回答

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

问题回答

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.

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.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签