2013-10-22 39 views
0

我想在頁面的底部中央的按鈕:的HTML頁腳內容的非中心

<footer> 
    <div class="centerContent"> 
     <input name="submit" type="submit" /> 
    </div> 
</footer> 

的CSS:

.centerContent { 
    text-align: center; 
} 

footer { 
    clear: both; 
    height: 100px; 
    position: absolute; 
    bottom: 0; 
} 

如果我刪除CS的「頁腳」部分,該按鈕當然不在頁面的底部,但至少它在頁面的水平中心。如果我將「頁腳」部分留在Css中,該按鈕位於頁面的底部,但是......它不再是水平居中了!任何人都知道爲什麼?非常感謝。

回答

2

對於水平對齊,您應該將頁腳擴展到全寬。將width:100%添加到footer風格。

.centerContent { 
    text-align: center; 
} 

footer { 
    clear: both; 
    height: 100px; 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
} 
+1

'頁腳:100%;'OOps :) –

+0

拼寫錯誤,thx – ole

+0

我會改變,但我把它留給你:)... anyways voteed .. –

0
footer { 
bottom: 0; 
clear: both; 
height: 100px; 
position: absolute; 
text-align: center; 
width: 100%; 
} 
0

試加寬度:100%到頁腳

footer { 
    width: 100%; 
    clear: both; 
    height: 100px; 
    position: absolute; 
    bottom: 0; 
} 

的位置是:絕對會讓頁腳失去它的默認寬度。

0

添加leftright屬性您footer,均設置爲0

footer { 
    clear: both; 
    height: 100px; 
    position: absolute; 
    bottom: 0; 

    /* add the following lines */ 
    left: 0; 
    right: 0; 
} 

如果添加width: 100%代替(如其他答案建議),您footer可能會蔓延的頁面,因爲任何額外的利潤和/或填充物。