解决前端footer无法保持在底部的问题

		在写页面是经常会遇到页面由于内容高度不够撑满而导致底部div(footer)无法稳定在底部,解决的方法:
  1. footer固定高度+绝对定位
    思路:将footer的父级div的最小高度(min-height)设为100%;然后将footer设为绝对定位(position:abusolute);同时父级div要空出footer的高度(padding-bottom);
    html 代码结构:
<div class="container">
	<header class="header"></div>
	<section class="section ">主体内容</section >
	<footer class="footer ">底部导航</footer >
</div>

css代码结构:

*{
    margin: 0;
    padding: 0;
}
html,body{
    height: 100%;
}

.container{
	/*保证footer是根据container来进行绝对定位*/
	position:relative;
	width:100%;
	min-height:100%;
	/*该处的值为底部div的值,如果低于底部div的高度,将会遮盖住主体内容*/
	padding-bottom:100px;
	box-sizing:border-box;	
}

header{
    width: 100%;
    height: 200px;
    background: #999;
}
.main{
    width: 100%;
    height: 200px;
    background: orange;
}

footer{
	position:absolute;
	width:100%;
	height:100px;
	bottom:0px;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值