Css Sticky Footer将页脚固定在页面底部

概述:Css Sticky Footer

如果页面内容不够长的时候,页脚块粘贴在视窗底部;如果内容足够长时,页脚块会被内容向下推送。

实现方法:

<!DOCTYPE html>
<html>
<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Css Sticky Footer</title>
    	<style>
		*{padding:0; margin:0}
		html,body{height:100%;}
		.wrapper{min-height:100%; height:100%; width: 100%;}
		.header{width:100%; height:100px;background-color:#999; }
		.main{padding-bottom:100px;}
		p{ height:800px; width:100%; background-color:green;}
		.footer{ position: relative;width:100%; height:100px; clear:both; margin:-100px auto 0; background-color:#666;}
		.clearfix{display:inline-block;}
		.clearfix:after{display:block;content:'.';height:0;line-height:0;clear:both;visibility:hidden;}
    	</style>
</head>
<body>
	<div class="wrapper">
		<div class="header"></div>
		<div class="main">
			<p></p>
		</div>
	</div>
	<div class="footer"></div>
</body>
</html>
总结:

1、可以通过改变p标签的高度,来查看底部的位置情况

2、main的padding-bottom值和footer的height值、margin-top负值要保持一致

3、wrapper的min-height值为100%,

4、html和body的height值为100%,wrapper继承父元素body的height

5、clearfix是清除浮动的Hack

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值