在不适用fixed的前提下,当内容较少时footer固定在页面底部
2016-03-08 17:54
387 查看
使用css,参考国外的一个解决方法:
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/How to use the CSS Sticky Footer on your website
Add the following lines of CSS to your stylesheet. The negative value for the margin in.wrapperis the same number as the height of
.footerand
.push. The negative margin should always equal to the full height of the footer (including any padding or borders you may add).
* { margin: 0; } html, body { height: 100%; } .wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -4em; } .footer, .push { height: 4em; }
Follow this HTML structure. No content can be outside of the .wrapper and .footer
divtags unless it is absolutely positioned with CSS. There should also be no content inside the .push
divas it is a hidden element that "pushes" down the footer so it doesn't overlap anything.
<html> <head> <link rel="stylesheet" href="layout.css" ... /> </head> <body> <div class="wrapper"> <p>Your website content here.</p> <div class="push"></div> </div> <div class="footer"> <p>Copyright (c) 2008</p> </div> </body> </html>
注意:
1. 注意footer body 的border/padding值会影响显示;
2. 当页面包含header时 .footer, .push 的设置会随之改变并不相等;
相关文章推荐
- [Java Web]敏感词过滤算法
- 2015.4 校赛回顾
- ElasticSearch 2 (18) - 深入搜索系列之控制相关度
- Android ActionBar 使用总结
- [转载]微服务实践(五):微服务的事件驱动数据管理
- STM32 USB学习笔记7
- app版本更新提醒
- substr截取中文字符出现乱码的解决办法
- Android 为应用增加可移动的悬浮窗口
- linux 增加swap方法
- SystemUI源码分析
- HDOJ 1573 X问题(中国剩余定理非互质版本)
- 如何调试binder?
- 8款PHP调试工具
- 四
- JQ手册
- CodeForces - 630N Forecast (解一元二次方程组)
- android缓存数据到本地
- 混合高斯模型去除背景
- windows的坑