方法一:

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. word 或者 WPS 使用两个目录的时候去掉中间的空格间隙

    在生成图表目录时,发现Office word图表目录中多个标题之间的空行无法删除,我是自己建的标签,比如“图1-”.“图2-”…….“表1-”.“表2-”…… 发现“图1-”.“图2-”…….“表1- ...

  2. 前端模块化小总结—commonJs,AMD,CMD, ES6 的Module

    随着前端快速发展,需要使用javascript处理越来越多的事情,不在局限页面的交互,项目的需求越来越多,更多的逻辑需要在前端完成,这时需要一种新的模式 --模块化编程 模块化的理解:模块化是一种处理 ...

  3. java 整型数据转换为小数类型 BigDecimal 装换为Double

    A,B为String类型 ,A-B=C BigDecimal A=(BigDecimal) map.get("A"); BigDecimal B=(BigDecimal) map. ...

  4. iOS手势识别器

    UIGestureRecognizer UIGestureRecognizer类,用于检测.识别用户使用设备时所用的手势.它是一个抽象类,定义了所有手势的基本行为.以下是UIGestureRecogn ...

  5. java语言描述 用递归打印字符串

    public class Test{ static private int n; public static void main(String[] args) { Test.n=76234; if(n ...

  6. ISAP学习笔记

    学完了ISAP,感觉心情舒畅,毕竟ISAP比Dinic好一点. 说到底ISAP其实是Dinic(不熟悉Dinic的人去我的博客找猴子课堂----最大流与最小割(看看思想),已经置顶)优化版,熟悉的人知 ...

  7. C# base64 转 byte[]

    string转成 Base64 形式的String //byte[] 转string byte[] b = Encoding.Default.GetBytes("字符串"); // ...

  8. C语言学习记录

    思路: 工具书: <c程序设计语言> R&K <linux C 编程一站式学习>

  9. HyperLedger Fabric 1.4 单机单节点部署(10.2)

    单机单节点指在一台电脑上部署一个排序(Orderer)服务.一个组织(Org1),一个节点(Peer,属于Org1),然后运行官方案例中的example02智能合约例子,实现转财交易和查询功能.单机单 ...

  10. python--复习之路的目录

    想要看时点链接看看,常来复习,温故而知新,可以为师矣. 1:基本类型 python--基本类型之字符串 python--基本类型之列表 python--基本类型之元组 python--基本类型之集合 ...