2014-01-11 20 views
0

內文本居中這是我的HTML:如何一個div

<div class="fourcol" align="center" ;="" style="float:;"> 
<h2 class="center" style="text-align: center;">More Mentors Announced Soon</h2> 

文本本身就是內容居中,但我想它在頁面內水平居中。我怎樣才能做到這一點?

這是我一直在使用它的CSS

.fourcol, { 
    position: relative; 
    float: left; 
    margin-right: 2.762430939%; 
    margin-bottom: 20px; 
    margin-top: 20px; 
} 


h2.center { 
    width: 50%; 
    margin: 0 auto; 
+1

可能重複[如何在水平和垂直居中文本?(http://stackoverflow.com/questions/19461521/how-to - 文字 - 水平 - 垂直) –

回答

0

http://jsfiddle.net/aDdge/

只需卸下寬度50%的線路

h2.center { 
    width: 50%; //remove this line 
    margin: 0 auto; 
} 

編輯

http://jsfiddle.net/aDdge/2/

h2.center { 
    margin-top: 34%; 
} 
+0

嗨, 謝謝你的幫助。不幸的是它仍然無法正常工作。 我在這裏粘貼了完整的CSS/HTML http://jsfiddle.net/RiverTam/sLK83/ – Kakarotto57

+0

沒問題。 我正試圖將「更多導師宣佈」文本移至頁面中心。 屏幕截圖:http://postimg.org/image/byc59dksj/ – Kakarotto57

+0

感謝您的持續支持AlienArrays 不幸的是,新方法也沒有工作。我開始認爲這可能是原始div class「fourcol」的錯。也許我應該創建一個新班級? – Kakarotto57

2

試試這個one.change類的fourcol to more

.more { 
    float: left; 
    width: 100%; 
} 
<div align="center" class="more"> 
<h2 style="text-align: center;" class="center">More Mentors Announced Soon</h2> 
</div>