页脚动态贴在底部需要满足以下两个条件:

  • 当主体的内容高度不超过可视区域高度的时候,页脚贴在页面底部。
  • 当主体的内容高度超过可视区域高度的时候,页脚将按正常布局。

方法一:footer高度固定+绝对定位

<body>
<header>header</header>
<main>content</main>
<footer>footer</footer>
</body>
html{height:100%;}
body{min-height:100%;margin:0;padding:0;position:relative;} header{background-color: #ffe4c4;}
main{padding-bottom:100px;background-color: #bdb76b;}
footer{position:absolute;bottom:0;width:100%;height:100px;background-color: #ffc0cb;}

方法二:footer高度固定+margin负值

<body>
<div class="container">
<header>header</header>
<main>main content</main>
</div>
<footer>footer</footer>
</body>
html,body{height:100%;margin:0;padding:0;}

.container{min-height:100%;}
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;}

方法三:css table实现的圣杯布局

<div class="wrapper">
<div class="header">头部</div>
<div class="main">
<div class="box sidebar">左侧栏</div>
<div class="box content">主体内容</div>
<div class="box sidebar">有侧栏</div>
</div>
<div class="footer">页脚底部</div>
</div>

body {
  background: @beige;
color: black;
} .wrapper {
height: 100%;
display: table;
width: 100%;
text-align: center;
} .header {
display: table-row;
height: 1px;
background: @yellow;
} .main {
height: 100%;
display: table;
width: 100%;
} .box {
display: table-cell;
} .sidebar {
width: 100px;
background: @orange;
} .footer {
display: table-row;
height:1px;
background: @green;
color: @beige;
} @orange: #BD4932;
@yellow: #FFD34E;
@green: #105B63;
@beige: #FFFAD5;
 
 
 

页面footer在底部的更多相关文章

  1. 网页布局中页面内容不足一屏时页脚footer固定底部

    方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...

  2. 页面滚动到底部自动 Ajax 获取文章

    页面滚动到底部自动 Ajax 获取文章  代码如下 复制代码 var _timer = {};function delay_till_last(id, fn, wait) {    if (_time ...

  3. CSS实现Footer固定底部,超过一屏自动撑开

    方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...

  4. 页面内容不够高footer始终位于页面的最底部

    相信很多前端工程师在开发页面时会遇到这个情况:当整个页面高度不足以占满显示屏一屏,页脚不是在页面最底部,用户视觉上会有点不好看,想让页脚始终在页面最底部,我们可能会想到用: 1.min-height来 ...

  5. 使用css方法使footer保持在页面的最底部

    使footer保持在页面的底部,是常见的需求,之前面试的时候也遇见了一个这样的问题,今天在这里记录下css实现的方式. 使footer保持在页面的底部,需要考虑header+content部分不够多的 ...

  6. 让footer始终位于页面的最底部

    http://www.cnblogs.com/wudingfeng/archive/2012/06/29/2569997.html html代码: <div class="contai ...

  7. Sticky Footer 绝对底部的两种套路

    最近面了好几个前端,工作经验有高有低,居然都不知道绝对底部是什么,也没有人能说出一种实现方式,让我不禁感慨前端领域的良莠不齐 绝对底部,或者说 Sticky Footer,是一种古老且经典的页面效果: ...

  8. 固定footer在底部

    作者:李宇链接:https://www.zhihu.com/question/23220983/answer/25880123来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  9. 始终让footer在底部

    1.footer保持在页面底部 需求: 我们希望footer能在窗口最底端,但是由于页面内容太少,无法将内容区域撑开,从而在 footer 下面会留下一大块空白 第一种方法:采用 flexbox布局模 ...

随机推荐

  1. Codeforces Round #548 (Div. 2) A. Even Substrings

    You are given a string 

  2. 洛谷P1601 A+B Problem(高精)

    题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 输出格式: 输 ...

  3. 将RedHat的yum更换为CentOS的yum

    CentOS6.8 脚本: #安装yum所需的包已经下载到本地 #!/bin/bashrpm -qa | grep yum | xargs rpm -e --nodepsrm -rf /etc/yum ...

  4. Pycharm中Git、Github的简单使用和配置

    Pycharm中Git.Github的使用 PyCharm本身自带了git,稍微配置一下就可以很好的在图形界面下进行Python项目的版本控制 配置Git 在配置前先新建一个项目,当然也可以打开已有的 ...

  5. Linux拖拽上传文件 lrzsz

    首先安装lrzsz 命令为:yum install lrzsz 安装完毕后直接将.tar.gz格式的文件拖如xshell的窗口内就会自动上传.

  6. lucene_05_solr配置

    什么是solr Solr.是Apache 下的一个顶级开源项目,采用Java 开发,它是基于Lucene 的全文搜索服务器.Solr 提供了比Lucene 更为丰富的查询语言,同时实现了可配置.可扩展 ...

  7. fzu 2132

    #include<stdio.h> double h; double tt; void s(long long m,long long n) { long long i,j,sum; j= ...

  8. Cloudera 5.8.3 SolrCloud+HDFS的索引数据备份和恢复。(需重启solr进程。)

    一.备份基于HDFS的solrCloud集合数据 1.确认要备份的solr文件夹. /solr/history_customer_collection_test 2.开启HDFS快照功能. hdfs ...

  9. PCA降维技术

    PCA降维技术 PCA 降维 Fly Time: 2017-2-28 主成分分析(PCA) PCA Algorithm 实例 主成分分析(PCA) 主成分分析(Principal Component ...

  10. uva 10479(找规律+递归)

    题意:有一个初始序列第一个数字是0. 规律是把前一次推出来的每个数字x.先接x个0,然后接x+1. 0 –> 1 –> 02 –> 1003 –> 02110004 那么这个序 ...