我遇到了一个经典问题,就是如何将页脚定位在浏览器的底部。我尝试了包括http://ryanfait.com/resources/footer-stick-to-bottom-of-page/在内的多种方法,但是都无法得到好的结果:在FF和IE中,我的页脚总是出现在浏览器窗口的中间。
在HTML中,我有这个简单的结构:
<form>
...
<div class=Main />
<div id=Footer />
</form>
这是与 CSS 底部问题相关的 CSS 代码:
*
{
margin: 0;
}
html, body
{
height: 100%;
}
#Footer
{
background-color: #004669;
font-family: Tahoma, Arial;
font-size: 0.7em;
color: White;
position: relative;
height: 4em;
}
.Main
{
position:relative;
min-height:100%;
height:auto !important;
height:100%;
/*top: 50px;*/
margin: 0 25% -4em 25%;
font-family: Verdana, Arial, Tahoma, Times New Roman;
font-size: 0.8em;
word-spacing: 1px;
line-height: 170%;
/*padding-bottom: 40px;*/
}
我到底做错了什么?我真的尝试了一切。如果我漏掉了任何有用的信息,请让我知道。提前感谢您的任何建议。致敬,
谢谢大家的回答。 以下方法可行:
position:absolute;
width:100%;
bottom:0px;
在IE中,将位置设置为fixed没有起作用(页脚仍然显示在浏览器中间),只有在FF中起作用。
flexbox
**非常容易实现。 - Fabrizio Bertoglio