美文网首页
“Sticky Footer”,多种实现

“Sticky Footer”,多种实现

作者: 一蓑烟雨任平生_cui | 来源:发表于2017-07-28 18:20 被阅读0次

所谓“Sticky Footer”是一种网页效果。即:页面的内容不足以撑开整个屏幕的高度时,footer置于屏幕底部;当内容超过一屏时,footer会随着内容下移,在内容底部。
如图:


Sticky Footer

html 布局如下:

 <div class="box">
  <div class="header"></div>
  <div class="content"></div>
  <div class="footer"></div>
</div>

css实现方案:

方案一: absolute
html,
body {
  /* 关键  */
  height: 100%;
}
.box {
  width: 100%;
  min-height: 100%; /* 关键 */
  position: relative; /* 相对定位 */
}
.header {
  height: 100px;
}
.content {
  padding-bottom: 100px;
}
.footer {
  height: 100px;
  position: absolute; /* 绝对定位 */
  bottom: 0;
  left: 0; /* IE 需要加  */   
}
方案二: flex

css代码

html,
body {
  /* 关键  */
  height: 100%;
}
.box {
  min-height: 100%; /* 关键 设置最小高度*/
  display: flex;
  flex-direction: column; /* 改变主轴方向 */
}
.header,
.footer  {
  height: 100px;
}
.content {
  flex: 1;
  /* 自适应 */
}
方案三:flex、flex-shrink、margin-top、vh(css单位)
.box {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.header {
  height: 100px;
  flex-shrink: 0;
}
.footer {
  height: 100px;
  /* 自动填满flex布局之后剩余的空间 */
  margin-top: auto;
  /* 子元素的缩小比例 默认为1: 空间不足时默认会缩小 */
  flex-shrink: 0;
}
方案四:flex、vh(css单位)
.box{
  /* 关键 */
  min-height: 100vh;  
  display: flex;
  flex-direction: column;
}
.header,
.footer {
  height: 100px;
}
.body{
  flex: 1;
}
方案五: min-height、calc
.header,
.footer {
  height: 100px;
}
.content {
  min-height: calc(100vh - 200px);
}
方案六:table
html,
body {
  height: 100%;
}
.box {
  display: table;
  width: 100%;
  min-height: 100%;
}
.header,
.footer {
  height: 100px;
}
.content {
  display: table-row;
  height: 100%;
}

相关文章

  • “Sticky Footer”,多种实现

    所谓“Sticky Footer”是一种网页效果。即:页面的内容不足以撑开整个屏幕的高度时,footer置于屏幕底...

  • web前端-Sticky Footer布局

    什么是Sticky Footer布局 Sticky Footer布局实现的效果是, 当页面中的内容高度小于屏幕高度...

  • css实现Sticky Footer

    所谓 “Sticky Footer”,指的就是一种网页效果: 如果页面内容不足够长时,页脚固定在浏览器窗口的底部;...

  • sticky footer的实现

    需求 实现footer永远在浏览器窗口的底部。当页面内容超过一屏时,在内容的最底端;当页面内容少于一屏时,foot...

  • sticky footer

    所谓的sticky footer就是指: 当页面内容超出屏幕,页脚模块会像正常页面一样,被推到内容下方,需要拖动滚...

  • sticky footer

    需求 如果页面内容不够长的时候,页脚块粘贴在视窗底部;如果内容足够长时,页脚块会被内容向下推送 实现

  • sticky footer

    一种完美的css绝对底部 手机端网页有时候会遇到这种布局要求:当内容很少时,footer位于窗口底部,当内容占满整...

  • sticky-footer布局的方法

    一、什么是sticky-footer布局?sticky-footer布局是一种经典的布局效果,可概况如下:如果页面...

  • 使用Flexbox实现Sticky footer

    Sticky footers设计是最古老和最常见的效果之一。做项目时,我们经常会碰到它:当页面不足一屏幕时,foo...

  • sticky footer布局

    实例 套路 一个展示内容content的容器wrapper 一个展示footer的容器 wrapper设置最小高度...

网友评论

      本文标题:“Sticky Footer”,多种实现

      本文链接:https://www.haomeiwen.com/subject/joyflxtx.html