text-align: center; not working in Firefox

今天做項目時,碰到div下的表格內容不能居中顯示。網上查了論壇,發現一個討論的帖子。(http://geekswithblogs.net/timh/archive/2006/04/19/75606.aspx)。現分享如下:

 

一、提出問題:

    下面這段代碼.

<style type="text/css">
.container{
  text-align: center;
  border: solid 1px blue;
}
</style>

<div class=container>
	<table>
		<tr><td>Text</td></tr>
	</table>
</div>

   在IE下"Text"居中顯示,FF下"Text"靠左顯示.

 

二、解決問題:

    方案1:

   

<style type="text/css">
.container{
  text-align: center;
  border: solid 1px blue;
}

table {
	margin-left:auto;
	margin-right:auto;
}
</style>

<div class=container>
	<table>
		<tr><td>Text</td></tr>
	</table>
</div>

 

    方案2:

    

<style type="text/css">
.container{
  text-align:-moz-center; /*FF*/
  #text-align: center; /*IE */
  border: solid 1px blue;
}
</style>

<div class=container>
	<table>
		<tr><td>Text</td></tr>
	</table>
</div>

 

    方案3:

   

<style type="text/css">
.container{
  border: solid 1px blue;
}
</style>

<center>
<div class=container>
	<table>
		<tr><td>Text</td></tr>
	</table>
</div>
</center>

 

 

三、論道摘錄:

    

   

     1.

寫道
# re: text-align: center; not working in Firefox 5/3/2006 1:44 AM phil

After some research, a better solution is table { margins: auto; }
since table is a block element (apparantly :)

 

     2.

寫道
# re: text-align: center; not working in Firefox 7/18/2007 2:18 PM kali_001
I tried this and able to see it in both FF and IE

.centerMyTable{
text-align:-moz-center;
!text-align:center;
}


But You know what, insteand of ! you can put any NON alph-numeric character. I tried with ^ ~ @ # $ % ^ & * ( ) _ + and it worked

Walalalalala

 

    3.

寫道
# re: text-align: center; not working in Firefox 10/18/2007 12:42 PM kees
<center> doesn't help you if you try to get you xhtml valid strict 1.0

 

   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章