方法一:

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. kali linux 安装TIM or QQ(CrossOver 安装 QQ)

    需要文件 http://www.crossoverchina.com/xiazai.html dpkg --add-architecture i386 apt-get update apt-get i ...

  2. Codeforces Round #483 (Div. 2)C题

    C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. hdu_5698_瞬间移动

    有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第nn行第mm列的格子有几种方案,答案对100000 ...

  4. 使用Wamp搭建Php本地开发环境,HBuilder调试

    初涉Php,此处做点笔记,希望下次不要能够轻松应对,至少不要在入同一个坑 本文摘要: wamp和HBuilder和Mysql5.7的安装包 Wamp的使用,包括80端口,443端口的占用问题 HBui ...

  5. Delphi 拦截滚轮事件不响应滚轮的上下滚动

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  6. Case Helper

    using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Que ...

  7. Git 与 SVN对比详解

    一.Git vs SVNGit 和 SVN 孰优孰好,每个人有不同的体验. Git是分布式的,SVN是集中式的 这是 Git 和 SVN 最大的区别.若能掌握这个概念,两者区别基本搞懂大半.因为 Gi ...

  8. C# set 跟 get

    可以在类里面 private string name; public string Name { get { return name; } set { name = value; } }

  9. go基础语法-循环语句

    1.基础定义 for语句的条件不需要括号(同if语句) ,golang里的循环只有for,没有while sum := 0 for i=0;i<100;i++ { sum += i } 2.条件 ...

  10. HyperLedger Fabric 1.4 问题汇总(16)

    16.1 在运行e2e_cli例子时,执行./network_setup.sh up,出现错误:网络搭建之network e2ecli_default not found 问题原因: End-2-En ...