页面主体高度不固定,如何让页面的footer始终在最底部

有时候我们的页面主体高度并不固定,而我们又不想让footer跟着主体高度变化而跑动,也许您会想到使用position:fixed;但是这并不能达到理想的要求,下面是我曾经在实际工作中用到的一种方法:
html:

<div class="wrapper>
    
content">主体内容div> div>

css:

html,body{
    height:100%;
}
.wrapper{
    min-height:100%;//使内容高度和body高度一样
    margin-bottom:-70px;向上缩减70px,使footer在可视范围
}
.content{
    margin-bottom:130px;//控制主体内容和底部高度之间距离
}
.footer{
    width:100%;
    height:70px;
    background-color:#ccc;
}

你可能感兴趣的:(css,css)