方法一:

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固定在页面最下方的更多相关文章

  1. 让footer固定在页面(视口)底部(CSS-Sticky-Footer)

    让footer固定在页面(视口)底部(CSS-Sticky-Footer) 这是一个让网站footer固定在浏览器(页面内容小于浏览器高度时)/页面底部的技巧.由HTML和CSS实现,没有令人讨厌的h ...

  2. 让footer固定在页面底部(CSS-Sticky-Footer)

    让footer固定在页面底部(CSS-Sticky-Footer)     这是一个让网站footer固定在浏览器(页面内容小于浏览器高度时)/页面底部的技巧.由HTML和CSS实现,没有令人讨厌的h ...

  3. HTML中footer固定在页面底部的若干种方法

    <div class="header"><div class="main"></div></div> <d ...

  4. footer固定在页面底部的实现方法总结

    方法一:footer高度固定+绝对定位 HTML代码: <body> <header>头部</header> <main>中间内容</main&g ...

  5. 在不适用fixed的前提下,当内容较少时footer固定在页面底部

    使用css,参考国外的一个解决方法: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/ How to use the CSS ...

  6. Footer固定在页面底部(CSS)

    <style type="text/css"> #wapper{ position: relative; /*重要!保证footer是相对于wapper位置绝对*/ h ...

  7. 利用CSS使footer固定在页面底部

    1.HTML基本结构 <!DOCTYPEhtml> <htmlxmlns="http://www.w3.org/1999/xhtml"> <headr ...

  8. 解决Web开发HTML页面中footer保持在页面底部问题

    如图所示如何实现footer在内容不足或者浏览器窗口变大变小的时候一直保持在底部呢?请看如下两种解决方案. 第一种方案: footer高度固定+绝对定位 (兼容性比较好完美兼容IE8+)思路:foot ...

  9. 【转载自W3CPLUS】如何将页脚固定在页面底部

    该文章转载自:W3CPLUS 大漠的文章 http://www.w3cplus.com/css/css-sticky-foot-at-bottom-of-the-page 以下为全文 作为一个Web的 ...

随机推荐

  1. shell脚本显示当前主机系统信息

    编写脚本/root/bin/systeminfo.sh, 当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小. vim /root/bin/system ...

  2. jquery头像上传剪裁插件cropper的前后台demo

    因为一个项目要做一个头像上传的功能,因此选择了使用jquery的头像插件cropper,cropper是一款使用简单且功能强大的图片剪裁jQuery插件,但是在使用的时候,有一个很大的坑需要注意,那就 ...

  3. 05JavaScript语句

    1.JavaScript 语句 JavaScript 语句是发给浏览器的命令. 这些命令的作用是告诉浏览器要做的事情. 2.分号 ; 分号用于分隔 JavaScript 语句. 通常我们在每条可执行的 ...

  4. 导入jar包和创建jar文件

    具体步骤   导入jar包 1.在第一个工程中编写工具类并运行生成.class文件 2.在myeclipse工具栏找到open in 文件夹图标找到.class文件所在的包,将其全部复制到某个盘符下( ...

  5. colspan和rowspan合并单元格

    最近在回顾html的时候,经常碰到一些table标签的问题,其中大多数都是合并单元格,所以在这里记录下自己的探究过程: <table cellpadding="0" cell ...

  6. 新系统设置 github 私钥

    1.首先我得重新在git设置一下身份的名字和邮箱(因为当初都忘了设置啥了,因为遇到坑了)进入到需要提交的文件夹底下(因为直接打开git Bash,在没有路径的情况下,根本没!法!改!刚使用git时遇到 ...

  7. 嵌入式C语言自我修养 01:Linux 内核中的GNU C语言语法扩展

    1.1 Linux 内核驱动中的奇怪语法 大家在看一些 GNU 开源软件,或者阅读 Linux 内核.驱动源码时会发现,在 Linux 内核源码中,有大量的 C 程序看起来“怪怪的”.说它是C语言吧, ...

  8. 在线升级python3.3版本

    1.sudo su 2.wget -P /usr/local  http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz    #指定下载到目录/ ...

  9. 几个简单if程序的细节比较与加法程序设计

    关于简单的if判断语句的不同写法: 输出0-9十个整数: 第一个程序: #include<stdio.h> #include<stdlib.h> int main() { ; ...

  10. Python3爬虫(十七) Scrapy框架(一)

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 1.框架架构图: 2.各文件功能scrapy.cfg 项目的配置文件items.py 定义了Item数据结构,所有 ...