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

最新文章

  1. WordPress目录文件结构详细说明
  2. DP专题训练之HDU 2955 Robberies
  3. 【iCore3 双核心板_FPGA】实验二十一:Niosii——基于内部RAM建立第一个软核
  4. AWR报告-数据库概要信息(一)
  5. make clean-kernel &amp;&amp; make kernel
  6. .net 中连接mysql
  7. 手写java虚拟机(一)——搭建环境
  8. JavaScript面试的完美指南(开发者视角)
  9. 快速搭建react项目骨架(按需加载、redux、axios、项目级目录等等)
  10. [Swift]LeetCode352. 将数据流变为多个不相交间隔 | Data Stream as Disjoint Intervals
  11. HTML- 标签语法
  12. python+selenium基础之XPATH轴定位(第二篇)
  13. shell 脚本不能执行多条?何解
  14. 【OCR技术系列之八】端到端不定长文本识别CRNN代码实现
  15. Apache Solr入门教程(初学者之旅)
  16. Lodop打印条码二维码设置多宽不一定是多宽
  17. 在k8s集群中,利用prometheus的jmx_exporter进行tomcat的JVM性能监控,并用grafana作前端展示
  18. 复习:JSP基本的语法(JSP凝视 + JSP指令 + JSP脚本元素 + JSP动作元素)
  19. Extjs4.x treepanel,treegrid 节点选择,选中某个节点
  20. POJ 3308 Paratroopers 最大流,乘积化和 难度:2

热门文章

  1. nfs服务共享,解决文件没有权限访问问题
  2. Eclipse取消汉化以及设置语言的方法
  3. 九十三:CMS系统之cms后台登录功能
  4. Python的一个bug,记录一下
  5. 深入解读TCP/IP
  6. redis 3.2.5单机版安装、使用、systemctl管理Redis启动、停止、开机启动
  7. mysql 批量kill locked 进程
  8. Java集合(1):Collections工具类中的static方法
  9. SVN 服务器 配置
  10. 生命周期中mounted和created的区别。