始终让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来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
随机推荐
- 【转】APIJSON,让接口见鬼去吧!
我: APIJSON,让接口和文档见鬼去吧! https://github.com/TommyLemon/APIJSON 服务端: 什么鬼? 客户端: APIJSON是啥? 我: APIJSON是一种 ...
- layui上传文件前加入确认提示
//上传文件 upload: function () { layui.use('upload', function () { var upload = layui.upload; //执行实例 var ...
- linux简单命令---网络编程
---------------------------------------------------------------------------------------------------- ...
- Vim/gVim 中文显示为乱码的解决办法
打开vimrc文件,在vim的安装目录下可以找到该文件,或在windows下是在vim/gvim下输入:edit $vim/_vimrc. 在文件的末尾添加一句 "set fileencod ...
- HBase管理与监控——彻底删除HBase数据
1.hadoop的bin目录下,执行命令以下命令清除Hbase数据 hadoop fs -rm -r /hbase 2.连接ZK,执行以下命令清除Hbase数据 rmr /hbase 3.重启ZK.重 ...
- 用shader实现流动的水面(webgl)
这段时间一直在看如何用shader绘制一个流动的水面,直接用贴图(高度图.法向贴图)实现的方法,这里就不讨论了. 搜了一大波博客资料,感觉存在如下一些问题: 1⃣️大多数资料都是基于opengl实现( ...
- springboot-多环境测试
1.application.properties中添加spring.profiles.active=test 2.同级目录下创建application-dev.properties.applicati ...
- Linux(CentOS)下安装tesseract-ocr以及配置依赖leptonica
下载 wget https://github.com/tesseract-ocr/tesseract/archive/4.1.0.tar.gz wget http://www.leptonica.or ...
- 安装zabbix4.0 LTS
一.环境准备 1.https://www.zabbix.com/download?zabbix=4.4&os_distribution=centos&os_version=7& ...
- ValueError: Object arrays cannot be loaded when allow_pickle=False
错误ValueError: Object arrays cannot be loaded when allow_pickle=False的解决 numpy最新版1.17以上版本与其他包不兼容问 ...