CSS Sticky Footer布局

效果:

1、若页面内容不够长时,页脚块粘贴在视窗底部(内容不够100%,页脚固定在页面底部);

2、若页面内容足够长时,页脚会被内容向下推送(内容超过100%,页脚随着滚动,在页面底部)。


固定的html结构和固定的css布局。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>CSS Sticky Footer</title>
	</head>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		html,body{
			height:100%;
			width:100%;
			overflow: hidden;
		}
		.oDiv{
			height:100%;
			width:100%;
			overflow: auto;
			background-color: rgba(7,17,27,.8);
			color:#fff;
		}
		.wrapper{
			width:100%;
			min-height:100%;
		}
		.content{
			padding-bottom: 60px;/*留出底部空间*/
		}
		.footer{
			position: relative;
			margin-top: -60px;/*显示底部内容*/
			height:60px;
			clear: both;
			box-sizing: border-box;
			border-top: 1px solid #ccc;
			text-align: center;
			line-height:60px;
		}
	</style>
	<body>
		<!--最外层div-->
		<div class="oDiv">
			<!--第二层div-wrapper-->
			<div class="wrapper">
				<!--第三层div-main-->
				<div class="content">
					content
					<!--ul若被注释,页面内容不超过100%,footer固定在页面底部-->
					<!--ul若未被注释,页面内容超出100%,滚动页面,footer在页面底部-->				
					<!--<ul>
						<li style="height:300px;width: 100%;background-color: #999;margin-bottom: 20px;text-align: center;line-height: 300px;">1</li>
						<li style="height:300px;width: 100%;background-color: #999;margin-bottom: 20px;text-align: center;line-height: 300px;">2</li>
						<li style="height:300px;width: 100%;background-color: #999;margin-bottom: 20px;text-align: center;line-height: 300px;">3</li>
					</ul>-->
				</div>
			</div>
			<!--第二层div-footer-->
			<div class="footer">
				footer
			</div>
		</div>
	</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值