Css Sticky Footer将页脚固定在页面底部
2017-05-19 10:17
736 查看
概述: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
如果页面内容不够长的时候,页脚块粘贴在视窗底部;如果内容足够长时,页脚块会被内容向下推送。
实现方法:
<!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
相关文章推荐
- 如何将页脚固定在页面底部(sticky footer)
- 让footer固定在页面(视口)底部(CSS-Sticky-Footer)
- 让页脚footer永远固定在页面的底部,而不是永远固定在显示器屏幕的底部的方法
- div footer标签css实现位于页面底部固定
- 怎么使用Sticky Footer代码(让页脚紧贴页面底部的方法)
- 利用CSS使footer固定在页面底部的实例代码
- 网页布局中页面内容不足一屏时页脚footer固定底部
- [文摘]怎么使用Sticky Footer代码(让页脚紧贴页面底部的方法)
- 利用CSS使footer固定在页面底部
- 【Web Trick 4】CSS 实现footer固定页面底部
- Footer固定在页面底部(CSS)
- 一道经典的css面试题。固定底部(sticky footer)
- 将页脚固定在页面底部的CSS实战
- A CSS Sticky Footer——CSS底部固定布局分析
- css 中 Sticky footers (让页脚紧贴页面底部的方法)
- Sticky Footer (让页脚永远停靠在页面底部,而不是根据绝对位置)
- Sticky Footer 让页脚紧贴页面底部
- 利用CSS使footer固定在页面底部
- 如何将页脚固定在页面底部
- 用css固定div层在页面顶部和底部(兼容IE6)