2011-05-04 125 views
0

我的文本居中我有這段代碼,它運行良好。頁腳信息在我的屏幕中間的底部:我怎樣才能使用Divs

div#footercenter p { font-size: 0.9em; } 

<div id="footercenter"> 
    <p>&#169; XXXX </p> 
</div> 

我想把它改成這樣:

div#footercenter {} 
div#footer-message { font-size: 0.9em; color: #EEEEEE; display: inline;} 
div#footer-copyright { font-size: 0.9em; color: #EEEEEE; display: inline; } 

<div id="footercenter"> 
    <div id="footer-copyright">xxx</div>| 
    <div id="footer-message">yyy</div> 
</div> 

現在我的文字是向左,而不是在中心。有沒有人有任何想法如何讓它回到中心?

戴夫

+0

人太多太快之前i型格的寬度答案.. :) – Vijay 2011-05-04 08:38:57

回答

1

應該是如此簡單:

#footercenter { 
    text-align:center; 
} 

但是你可能需要這樣做,以及如果你有其他風格的干擾:

#footercenter div { 
    float:none; 
    display:inline; /* or inline-block */ 
} 
0

嘗試

div#footercenter { 
    text-align:center; 
} 

<div id="footercenter"> 
    <span id="footer-copyright">xxx</span>| 
    <span id="footer-message">yyy</span> 
</div> 
1

一個<div>是應該用來定義元素的集合,而不是明確針對文本內容的塊元素。您的標記沒有任何問題,但是您已經設置了div,然後顯示:inline,這意味着它們只佔用其內容的寬度。默認情況下,divs也會聚集在左邊。

更好的方法是將文本包含在2個span元素中,然後簡單地將父div的text-align屬性設置爲居中。

請參閱以下內容;

div#footercenter { font-size: 0.9em; color: #EEEEEE; text-align:center; } 

<div id="footercenter"> 
    <span>xxx</span>| 
    <span>yyy</span> 
</div> 
0

重寫你的footercenter類作爲

div#footercenter {text-align:center;} 
0

設置你想要的text-align屬性應用到,然後分配text-align : center.