HTML的footer置于页面最底部的方法
方法一:footer高度固定+绝对定位
<html>
<head>
<style type="text/css">
html{height:%;}
body{min-height:%;margin:;padding:;position:relative;} .header{background-color: #ffe4c4;}
.main{padding-bottom:100px;background-color: #bdb76b;}/* main的padding-bottom值要等于或大于footer的height值 */
.footer{position:absolute;bottom:;width:%;height:100px;background-color: #ffc0cb;}
</style>
</head> <body>
<div class="header">header</div>
<div class="main">main content</div>
<div class="footer">footer</div>
</body>
</html>
效果:

方法二:footer高度固定+margin负值
<html>
<head>
<style type="text/css">
html,body{height:%;margin:;padding:;} .container{min-height:%;}
.header{background-color: #ffe4c4;}
.main{padding-bottom:100px;background-color: #bdb76b;}/* main的padding-bottom值要等于或大于footer的height值 */
.footer{height:100px;margin-top:-100px;background-color: #ffc0cb;}/* margin-top(负值的)高度等于footer的height值 */
</style>
</head> <body>
<div class="container">
<div class="header">header</div>
<div class="main">main content</div>
</div>
<div class="footer">footer</div>
</html>
方法三:footer高度任意+js
<html>
<head>
<style type="text/css">
html,body{margin:;padding: ;}
.header{background-color: #ffe4c4;}
.main{background-color: #bdb76b;}
.footer{background-color: #ffc0cb;} /* 动态为footer添加类fixed-bottom */
.fixed-bottom {position: fixed;bottom: ;width:%;}
</style> <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
function footerPosition(){
$("footer").removeClass("fixed-bottom");
var contentHeight = document.body.scrollHeight,//网页正文全文高度
winHeight = window.innerHeight;//可视窗口高度,不包括浏览器顶部工具栏
if(!(contentHeight > winHeight)){
//当网页正文高度小于可视窗口高度时,为footer添加类fixed-bottom
$("footer").addClass("fixed-bottom");
} else {
$("footer").removeClass("fixed-bottom");
}
}
footerPosition();
$(window).resize(footerPosition);
});
</script>
</head> <body>
<div class="header">header</div>
<div class="main">main content</div>
<div class="footer">footer</div>
</body>
</html>
ref: https://segmentfault.com/a/1190000004453249
HTML的footer置于页面最底部的方法的更多相关文章
- HTML5将footer置于页面最底部的方法(CSS+JS)
JavaScript: <script type="text/javascript"> $(function(){ function footerPosition(){ ...
- HTML的footer置于页面最底部
vue项目中,使用element-ui的布局,仍然出现footer不固定页面底部的情况,网上找到的一个管用的 方法是:footer高度固定+绝对定位 <html> <head> ...
- [JavaScript] css将footer置于页面最底部
<!-- 父层 --> <div id="wapper"> <!-- 主要内容 --> <div id="main-conten ...
- 记一些让footer始终位于网页底部的方法
上次说把网页的头部和尾部分离出来作为一个单独的文件,所有网页共用,这样比较方便修改,然而,,,我发现某些方法里尾部会紧跟在头部后面,把内容挤在下面..而且有的页面内容少的话不能把尾部挤到最下面,所以, ...
- footer始终在页面最底部的方法(问题待检验)
一.css方法 <style type="text/css"> html,body{ height: 100%; } body{ display: flex; flex ...
- 将HTML页面页脚固定在页面底部(多种方法实现)
当一个HTML页面中含有较少的内容时,Web页面的footer部分随着飘上来,处在页面的半腰中间,给视觉效果带来极大的影响,接下来为大家介绍下如何将页脚固定在页面底部,感兴趣的朋友可以了解下 作为一个 ...
- vue实现部分页面导入底部 vue配置公用头部、底部,可控制显示隐藏
vue实现部分页面导入底部 vue配置公用头部.底部,可控制显示隐藏 在app.vue文件里引入公共的header 和 footer header 和 footer 默认显示,例如某个页面不需要显示h ...
- 网站设计:将Footer固定在浏览器底部
在设计网站的时候,如果你某个页面的内容没有满屏,那你的footer会离浏览器底部很远,整体看起来很难看,这里用JavaScript提供一种方法来将footer固定在浏览器底部. function fi ...
- div+css页面右侧底部悬浮层
效果体验:http://hovertree.com/texiao/css/23/ 效果图: 代码如下: <!DOCTYPE html> <html> <head> ...
随机推荐
- Python 中的几种复制文件的用法
1. os.system Python code import os import tempfile filename1 = tempfile.mktemp (".txt") #产 ...
- Jquery重新学习之八[Ajax运用总结B]
上一篇简单介绍普通javascript以及Jquery的AJAX方法,其中Jquery.ajax()是功能比较强悍的底层方法,可以更多地关注实现过程中的细节:除Jquery.ajax()方法外,Jqu ...
- iOS中使用iCloud一些须要注意的地方(Xcode7.2)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 在自己的App中怎样使用iCloud有非常多文章能够查阅,这里 ...
- 最低位 【杭电-HDOJ-1196】 附题
/* Lowest Bit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 查看80port是否被占用
windows下命令: netstat -ano|findstr "0.0:80"
- eclipse中查看某个方法(函数)被谁调用
用了好久一直不知道eclipse中怎样实现vs中查找全部引用的功能,今天最终发现了哈哈 选中要查找的方法名,右键->References->Workspace 能够定位到详细的调用位置,快 ...
- hibernate 在做更新和删除的时候一定要把事务开启
在做更新和删除的时候一定要把事务开启 在做更新和删除的时候一定要把事务开启 在做更新和删除的时候一定要把事务开启 重要的事情说三遍!!! curd之前配置文件 <property name=&q ...
- 使用Ubuntu12.04创建无线WiFi热点供手机上网
[日期:2012-10-10] 1,单击右上角网络连接管理器(记得打开电脑的无线网络开关),选择“编辑连接…” 2,选择无线,然后单击添加. 3,{无线}输入连接名称,如longer,然后 ...
- 【LeetCode】73. Set Matrix Zeroes (2 solutions)
Set Matrix Zeroes Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do i ...
- ubuntu下apache和mysql的命令
// Apache //Task: Start Apache 2 Server /启动apache服务 # /etc/init.d/apache2 start //or $ sudo /etc/ini ...