将footer固定在页面最下方
方法一:
HTML结构:
<div id="id_wrapper">
<div id="id_header">
Header Block
</div>
<div id="id_content">
Content Block
</div>
<div id="id_footer">
Footer Block
</div>
</div>
CSS结构:
html, body {
/* 設定body高度為100% 拉到視窗可視的大小 */
height: 100%;
}
*{
padding:;margin:;
}
#id_wrapper {
/* 設定高度最小為100%, 如果內容區塊很多, 可以長大 */
min-height: 100%;
/* 位置設為relative, 作為footer區塊位置的參考 */
position: relative;
}
#id_header {
/* 設定header的高度 */
height: 40px;
box-sizing: border-box;
background: green;
}
#id_content {
/* 留出footer區塊的空間 padding-bottom与footer高度相同 */
25
padding-bottom: 40px;
/*height: 800px;*/
background: #666;
}
#id_footer {
/* 設定footer的高度 */
height: 40px;
box-sizing: border-box;
/* 設定footer絕對位置在底部 */
position: absolute;
bottom:;
/* 展開footer寬度 */
width: 100%;
background: yellow;
}
方法二:footer高度固定+绝对定位
html结构:
<div class="header">header</div>
<div class="mian">main content</div>
<div class="footer">footer</div>
CSS设置:
html{height:100%;}
body{min-height:100%;margin:;padding:;position:relative;}
.header{background-color: #ffe4c4;height:40px;width: 100%;}
.main{padding-bottom:100px;width: 100%;background-color: #bdb76b;}/* main的padding-bottom值要等于或大于footer的height值 */
.footer{position:absolute;bottom:;width:100%;height:100px;background-color: #ffc0cb;}
首先,设置body的高度至少充满整个屏幕,并且body作为footer绝对定位的参考节点;
其次,设置main(footer前一个兄弟元素)的padding-bottom值大于等于footer的height值,以保证main的内容能够全部显示出来而不被footer遮盖;
最后,设置footer绝对定位,并 设置height为固定高度值 。
方法三:footer高度任意+js
HTML结构:
<body>
<header>header</header>
<main>main content</main>
<footer>footer</footer>
</body>
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:100%;}
js代码:
$(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);
});
将footer固定在页面最下方的更多相关文章
- 让footer固定在页面(视口)底部(CSS-Sticky-Footer)
让footer固定在页面(视口)底部(CSS-Sticky-Footer) 这是一个让网站footer固定在浏览器(页面内容小于浏览器高度时)/页面底部的技巧.由HTML和CSS实现,没有令人讨厌的h ...
- 让footer固定在页面底部(CSS-Sticky-Footer)
让footer固定在页面底部(CSS-Sticky-Footer) 这是一个让网站footer固定在浏览器(页面内容小于浏览器高度时)/页面底部的技巧.由HTML和CSS实现,没有令人讨厌的h ...
- HTML中footer固定在页面底部的若干种方法
<div class="header"><div class="main"></div></div> <d ...
- footer固定在页面底部的实现方法总结
方法一:footer高度固定+绝对定位 HTML代码: <body> <header>头部</header> <main>中间内容</main&g ...
- 在不适用fixed的前提下,当内容较少时footer固定在页面底部
使用css,参考国外的一个解决方法: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/ How to use the CSS ...
- Footer固定在页面底部(CSS)
<style type="text/css"> #wapper{ position: relative; /*重要!保证footer是相对于wapper位置绝对*/ h ...
- 利用CSS使footer固定在页面底部
1.HTML基本结构 <!DOCTYPEhtml> <htmlxmlns="http://www.w3.org/1999/xhtml"> <headr ...
- 解决Web开发HTML页面中footer保持在页面底部问题
如图所示如何实现footer在内容不足或者浏览器窗口变大变小的时候一直保持在底部呢?请看如下两种解决方案. 第一种方案: footer高度固定+绝对定位 (兼容性比较好完美兼容IE8+)思路:foot ...
- 【转载自W3CPLUS】如何将页脚固定在页面底部
该文章转载自:W3CPLUS 大漠的文章 http://www.w3cplus.com/css/css-sticky-foot-at-bottom-of-the-page 以下为全文 作为一个Web的 ...
随机推荐
- VSCode 配置 Python
假设 Anaconda 和 VSCode 都安装好了. 安装插件 VSCode 自带的 python 高亮不是很好,这里我们用 One Dark Pro 插件, 以及安装 Python 插件. 设定 ...
- DMVPN的实验模拟与分析
此篇博客正在介绍的是下图中的DMVPN: 为什么会出现DMVPN这个技术呢? 在这篇博客中https://www.cnblogs.com/huwentao/p/9355240.html介绍过Dynam ...
- Go正则处理
Go语言通过regexp标准包为正则表达式提供了官方支持 包中有三个函数判定是否匹配,匹配返回true,否则返回false,这三个函数只是输入源不同 func Match(pattern string ...
- 20145202马超 2016-2017-2 《Java程序设计》第10周学习总结
学号 2016-2017-2 <Java程序设计>第X周学习总结 教材学习内容总结 一.网络编程 1.网络概述 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事 ...
- 20145209刘一阳 《网络对抗》Exp7 网络欺诈技术防范
20145209刘一阳 <网络对抗>Exp7 网络欺诈技术防范 一.应用SET工具建立冒名网站 要让冒名网站在别的主机上也能看到,需要开启本机的Apache服务,并且要将Apache服务的 ...
- WPF程序,运行时,结束时,要运行的操作(自动保存,检查单程序)
/// <summary> /// App.xaml 的交互逻辑 /// </summary> public partial class App : Application { ...
- 【原创】Odoo开发文档学习之:构建接口扩展(Building Interface Extensions)(边Google翻译边学习)
构建接口扩展(Building Interface Extensions) 本指南是关于为Odoo的web客户创建模块. 要创建有Odoo的网站,请参见建立网站;要添加业务功能或扩展Odoo的现有业务 ...
- ASP.NET MVC 微信JS-SDK认证
layout: post title: ASP.NET MVC 微信JS-SDK认证 category: .net date: 2016-11-01 00:00:00 tags: .net javas ...
- YARN 与Maprd 配置
<!-- yarn 配置 --> <!-- yarn-sit.xml --> <property> <name>yarn.resourcemanager ...
- NB-IOT移植移动onenet基础通信套件之Object_ID,实例ID,资源ID
1. 访问是按照分层的,Object_ID/实例ID/资源ID,对应每一层ID的数据类型,目前是分为3层,一个实例下面可以有多个实例id,对下面的数据结构来说,如果是资源ID的话,类型只能是asBuf ...