2011-03-23 26 views
2

中間到目前爲止,我有這樣的:棒在TOP的DIV和使用CSS

<style> 
#success_notification { 
position:absolute; 
top:0; 
width:30%; 
text-align:center; 
    font:20px Georgia; 
    color:#5C5C5C; 
    background:#F2FFED; 
    padding:10px; 
} 

</style> 

<div style="margin:0 auto;"><div id='success_notification'>TESTING.</div></div> 

和DIV停留在左邊...還是。我究竟做錯了什麼?謝謝。

+1

'文本align'沒有中心,你DIV阻止它爲中心的DIV塊中的文本。 – 2011-03-23 22:03:19

回答

5

您沒有設置leftright,導致你的絕對定位的元素默認爲0的left試試這個:

#success_notification { 
    position: absolute; 
    top: 0; 
    left: 35%; 
    width: 30%; 
    text-align: center; 
    font: 20px Georgia; 
    color: #5C5C5C; 
    background: #F2FFED; 
    padding: 10px; 
} 
+0

謝謝。我會盡快將其標記出來。 – nn2 2011-03-23 22:09:33

0

試試這個:

#success_notification { 
    position:absolute; 
    top:0; 
    left: 50%; 
    width:30%; 
    text-align:center; 
    font:20px Georgia; 
    color:#5C5C5C; 
    background:#F2FFED; 
    padding:10px; 
} 
2

在這裏你去。

刪除位置:絕對,添加了邊距:auto爲樣式,向外部div添加寬度100%。適用於我。

<style> 
#success_notification { 
top:0; 
width:30%; 
margin: auto; 
text-align:center; 
    font:20px Georgia; 
    color:#5C5C5C; 
    background:#F2FFED; 
    padding:10px; 
} 

</style> 

<div style="width: 100%; margin:0 auto;"><div id='success_notification'>TESTING.</div></div> 
0

...甚至:

向左飄浮;

...或:

浮動:權

這個偉大工程在所有瀏覽器