始终让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来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
随机推荐
- gitlib的安装
下载ruby yum -y install gcc gcc-c++ make wget https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.9.tar. ...
- 如何快速通过json构建javabean对象(Intellij IDEA-->GsonFormat使用教程)
和第三方对接的时候,返回给我们的json时参数字段多是很常见的现象,所以我们手动去创建javabean肯定是要花费不少时间,博主在网上找到了很多种,可用通过json自动生成javabean的工具,这里 ...
- Spring Boot 2.0 集成 Druid 数据源
一.Maven项目依赖 <!-- 开发者工具(热部署 修改classpath下的文件springboot自动重启) --> <dependency> <groupId&g ...
- lumen怎么得到当前Uri的控制器、Action、路由规则
<?php namespace App\Http\Controllers; class HelloController extends Controller { public function ...
- python #!/usr/bin/python作用
#!/usr/bin/python指定用什么解释器运行脚本以及解释器所在的位置 # -*- coding: utf-8 -*-用来指定文件编码为utf-8的PEP 0263 -- Defining P ...
- Mac 常用配置(JDK切换,ll命令设置)
打开 /Users/用户/.bash_profile文件 1.JDK切换,添加如下内容 export JAVA_6_HOME=`/usr/libexec/java_home -v 1.6` # 设置 ...
- vue ts ,vue使用typescript,三种组件传值方式
参考链接:https://juejin.im/post/5c55156f6fb9a049ef270541
- csv文件的读取写法 from Udacity
长版本 import unicodecsv enrollments_filename = 'C:\\Users\\xxxxx\\Desktop\\try.csv' enrollments = [] f ...
- SQL 拼接字符串 使用IN查询方法
问题描述 当在 SQL SERVER 中查询的时候,同事遇到一个字段存储的字符串为用逗号分隔的主键 ID 值,格式为:1,2,3,4,这时候需要查询符合条件的所有数据,所以选择使用 IN 查询,但是直 ...
- windows下安装和配置SNMP
window snmp服务开启及测试 转自:https://blog.csdn.net/qq_33314107/article/details/80031446 一 安装 二 开启服务 Linux下安 ...