1.footer保持在页面底部

需求:

我们希望footer能在窗口最底端,但是由于页面内容太少,无法将内容区域撑开,从而在 footer 下面会留下一大块空白

第一种方法:采用 flexbox布局模型 

(将 body 的 display 属性设置为 flex, 然后将方向属性设置为列, (默认是行,也就是横向布局);同时,将html 和 body 元素的高度设置为100%,使其充满整个屏幕)

代码:

<div id="container">
<header>header</header>
<section class="main">main</section>
<footer>footer</footer>
</div>
*{
margin:;
padding:;
}
html,body{
height: 100%;
}
#container{
display: flex;
flex-direction: column;
height: 100%;
}
header{
background: #999;
flex: 0 0 auto;
}
.main{
background: orange;
flex: 1 0 auto;
}
footer{
background: #333;
flex: 0 0 auto;
}

第二种方法:采用footer高度固定+绝对定位

(注意:footer的父层的最小高度是100%,footer设置成相对于父层位置绝对(absolute)置底(bottom:0),父层内要预留(padding-bottom)footer的高度,保证main的内容能够全部显示出来而不被footer遮盖)

代码:

<div id="container">
<header>header</header>
<section class="main">main</section >
<footer>footer</footer>
</div>
*{
margin:;
padding:;
}
html,body{
height: 100%;
}
#container{
/*保证footer是相对于container位置绝对定位*/
position:relative;
width:100%;
min-height:100%;
/*设置padding-bottom值大于等于footer的height值,以保证main的内容能够全部显示出来而不被footer遮盖;*/
padding-bottom: 100px;
box-sizing: border-box;
}
header{
width: 100%;
height: 200px;
background: #999;
}
.main{
width: 100%;
height: 200px;
background: orange;
}
footer{
width: 100%;
height:100px; /* footer的高度一定要是固定值*/
position:absolute;
bottom:0px;
left:0px;
background: #333;
}

 第三种:固定在网页底部且居中

html {
height: 100%;
}
body {
margin:;
padding:;
min-height: 100%;
position: relative;
}
#footer{
position: absolute;
left:;
right:;
bottom:;
color: #969696;
text-align: center;
}

附加大佬的常用居中总结:

https://juejin.im/post/58f818bbb123db006233ab2a#heading-6

始终让footer在底部的更多相关文章

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

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

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

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

  3. DIV 始终位于文档底部

    DIV 始终位于文档底部 设置body为绝对定位,最小显示高度为:100%,宽度为:100%: 设置底部显示块为绝对定位,bottom: 0,是body元素的最后一个直接子元素: 设置底部块元素同级元 ...

  4. footer始终在页面最底部的方法(问题待检验)

    一.css方法 <style type="text/css"> html,body{ height: 100%; } body{ display: flex; flex ...

  5. 让footer始终待在页面底部

    1.把html和body的height属性设为100%;保证content的高度能撑满浏览器; 2.把#content的高度也设置为100% ,但是这里我们使用了“min-height”属性,而不是的 ...

  6. CSS + DIV 让页脚始终保持在页面底部

    来源:David's Blog     http://www.DavidQiu.com/ 文章链接:http://blog.davidqiu.com/post/2013-06-17/400517539 ...

  7. 让footer在底部(测试它人方法)

    要求:网页布局中,页脚在底部.内容不够一页时,在底部.内容超过一页时,出现卷动条,页脚也在被挤到底部 1.测试的这个文章介绍的办法   链接: http://www.cnblogs.com/cheny ...

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

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

  9. 固定footer在底部

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

随机推荐

  1. LC 957. Prison Cells After N Days

    There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...

  2. 【C/C++开发】__stdcall,__cdecl,__fastcall的区别

    __stdcall和__cdecl的区别 __stdcall和__cdecl是两种函数名字修饰.(注意是连续的两个下划线) Windows上 windows上不管是C还是C++,默认使用的都是__st ...

  3. 【并行计算-CUDA开发】__syncthreads的理解

    __syncthreads()是cuda的内建函数,用于块内线程通信. __syncthreads() is you garden variety thread barrier. Any thread ...

  4. hbase增量和全量备份

    1.星期五全量备份星期四23:59:59的数据,星期一全量备份到星期日23:59:59的数据,其他的增量备份,备份前一天00:00:00  -  23:59:59的数据 * * /opt/prodfu ...

  5. shell sed 替代1

    sed -e '/-DLUA_USE_LINUX/s/-lreadline/-lreadline -lncurses/g' Makefile > tmp mv tmp Makefile 全局换- ...

  6. 非阻塞IO可以等同异步IO嘛?

    脑壳短路的一瞬间,黑人问号? 在这个问题之前,我们先了解下IO的过程,下图是异步IO,做个参照(图片随便找的,侵权联系小弟删除) 简单叙述下windows同步IO的流程(图片描述的是异步IO) 1.调 ...

  7. 服务器:消息18456,级别16,状态1 用户‘sa’登录失败解决方法

    无法连接到服务器**:  服务器:消息18456,级别16,状态1   [Microsoft][ODBC   SQL   Server   Driver][Sql   server]   用户 'sa ...

  8. paramiko模块(远程操作服务器)

    paramiko模块(远程操作服务器) django+paramkio实现远程某些服务器执行命令+上传文件 用于帮助开发者通过代码远程连接服务器,并对服务器进行操作. pip3 install par ...

  9. MySQL-存储引擎-创建表-字段数据类型-严格模式-字段约束-键-02

    目录 扩展点 查看服务端字符.IP.端口配置 取消本次错误输入 例外情况 database 数据库操作 table 数据表操作 查看MySQL存储引擎 常见几个存储引擎 InnoDB MyISAM M ...

  10. JavaScript-checkbox标签-隐藏、显示、全选、取消和反选等操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...