2013-10-22 43 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可能会蔓延的页面,因为任何额外的利润和/或填充物。