始终让footer在底部
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在底部的更多相关文章
- 网页布局中页面内容不足一屏时页脚footer固定底部
方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...
- CSS实现Footer固定底部,超过一屏自动撑开
方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...
- DIV 始终位于文档底部
DIV 始终位于文档底部 设置body为绝对定位,最小显示高度为:100%,宽度为:100%: 设置底部显示块为绝对定位,bottom: 0,是body元素的最后一个直接子元素: 设置底部块元素同级元 ...
- footer始终在页面最底部的方法(问题待检验)
一.css方法 <style type="text/css"> html,body{ height: 100%; } body{ display: flex; flex ...
- 让footer始终待在页面底部
1.把html和body的height属性设为100%;保证content的高度能撑满浏览器; 2.把#content的高度也设置为100% ,但是这里我们使用了“min-height”属性,而不是的 ...
- CSS + DIV 让页脚始终保持在页面底部
来源:David's Blog http://www.DavidQiu.com/ 文章链接:http://blog.davidqiu.com/post/2013-06-17/400517539 ...
- 让footer在底部(测试它人方法)
要求:网页布局中,页脚在底部.内容不够一页时,在底部.内容超过一页时,出现卷动条,页脚也在被挤到底部 1.测试的这个文章介绍的办法 链接: http://www.cnblogs.com/cheny ...
- Sticky Footer 绝对底部的两种套路
最近面了好几个前端,工作经验有高有低,居然都不知道绝对底部是什么,也没有人能说出一种实现方式,让我不禁感慨前端领域的良莠不齐 绝对底部,或者说 Sticky Footer,是一种古老且经典的页面效果: ...
- 固定footer在底部
作者:李宇链接:https://www.zhihu.com/question/23220983/answer/25880123来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
随机推荐
- CPU排行-台式
此文已经于2017年11月1日更新!来源于极速空间 实际对比: intel i3-7100(双核四线程) CPU性能远超过 AMD X4 860K(四核四线程) intel i5-7500(四核四线程 ...
- nginx不间断服务平滑升级
(1)备份旧的nginx和配置文件 cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/bak_nginx #备份旧版程序 cp /usr/loc ...
- Mysql - 面试题 获取每个学生的最高成绩
题目 如下一个表, 三列, 姓名, 课程, 以及成绩, 现在想要得到知道每个学生最高成绩的课程名字. 解题
- Docker容器时间与主机时间相差8小时
查看主机时间 [root@localhost ~]# date 2016年 07月 27日 星期三 22:42:44 CST 查看容器时间 root@b43340ecf5ef:/# date Wed ...
- Kettle实现从mysql中取2张表数据关联的数据,并写入到mongodb中
1 建立转换,并设置DB连接到mysql 选中DB连接:连接类型选择MySQL,输入主机名称,数据库名称,端口号,用户名,密码 输入连接名称,点击确定.(可以先点击测试,测试一下是否连接成功) 如下图 ...
- Markov logic network
A Markov logic network (or MLN) is a probabilistic logic which applies the ideas of a Markov network ...
- Angular中ngx-image-cropper图片裁剪的使用
GitHub示例源码地址:https://github.com/luoruiemail/ngx-image-cropper 下载下来之后,执行yarn install安装相关node_modules包 ...
- 手写Indexof
String.prototype.indexO = function(st){ // console.log(this.length); let str = this; var j = 0; let ...
- 生产环境Crontab专业实例
1)书写Crontab定时任务多个基本要领 1.规范定时任务两例 例1:每分钟打印一次自己名字的全拼到 “/server/log/自己命名的文件” 中
- LESSON 6- Quantization
如果输入本身就是离散的(比如text, computer files…), 对于这种discrete sources不需要量化可以直接进行离散信源编码. 如果输入是waveform(比如声音),取样为 ...