HTML-CSS实现 | 在页面不满时,footer也为于底部

代码中的div要为footer的父框

html{
    height: 100%;    /*保证页面高度撑满屏幕*/
}
body{
    height: 100%;
}
body>div{
    /*保证footer是相对于div位置绝对定位*/
    position:relative;  
    width:100%;
    min-height:100%; 
    /*设置padding-bottom值大于等于footer的height值,以保证main的内容能够全部显示出来而不被footer遮盖;*/  
    padding-bottom: 100px;  
    box-sizing: border-box;
}

footer的样式

footer{
    position:absolute; /*footer在div的底部*/
    bottom:0px;
    width: 100%;
}

 

posted @ 2020-09-15 20:04  海胆Sur  阅读(24)  评论(0)    收藏  举报  来源