• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >CSS > 详解CSS五种方式实现Footer置底

详解CSS五种方式实现Footer置底

作者:小小赵老汉 字体:[增加 减小] 来源:互联网 时间:2017-08-06

本文主要包含css,footer,css,footer固定在底部,css,footer,绝对底部等相关知识,小小赵老汉 希望在学习及工作中可以帮助到您

页脚置底(Sticky footer)就是让网页的footer部分始终在浏览器窗口的底部。

当网页内容足够长以至超出浏览器可视高度时,页脚会随着内容被推到网页底部;但如果网页内容不够长,置底的页脚就会保持在浏览器窗口底部。

方法一:将内容部分的margin-bottom设为负数

<div class="wrapper">
    <!-- content -->
    <div class="push"></div>
</div>
<div class="footer">footer</div>
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
.wrapper {
  min-height: 100%;  
  margin-bottom: -50px; /* 等于footer的高度 */
}
.footer, .push {
  height: 50px;
}

1、这个方法需要容器里有额外的占位元素(div.push)。

2、div.wrapper的margin-bottom需要和div.footer的-height值一样,注意是负height。

方法二:将页脚的margin-top设为负数

给内容外增加父元素,并让内容部分的padding-bottom与页脚的height相等。

<div class="content">
  <div class="content-inside">
    <!-- content -->
  </div>
</div>
<div class="footer">footer</div>
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
.content {
  min-height: 100%;
}
.content-inside {
  padding: 20px;
  padding-bottom: 50px;
}
.footer {
  height: 50px;
  margin-top: -50px;
}

方法三:使用calc()设置内容高度

<div class="content">
  <!-- content -->
</div>
<div class="footer">footer</div>
.content {
  min-height: calc(100vh - 70px);
}
.footer {
  height: 50px;
}

这里假设div.content和div.footer之间有20px的间距,所以70px=50px+20px

方法四:使用flexbox弹性盒布局

以上三种方法的footer高度都是固定的,如果footer的内容太多则可能会破坏布局。

<div class="content">
  <!-- content -->
</div>
<div class="footer">footer</div>
html {
  height: 100%;
}
body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.content {
  flex: 1;
}

方法五:使用Grid网格布局

<div class="content">
  <!-- content -->
</div>
<div class="footer">footer</div>
html {
  height: 100%;
}
body {
  min-height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
}
.footer {
  grid-row-start: 2;
  grid-row-end: 3;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持微课江湖。

您可能想查找下面的文章:

  • css小技巧
  • 各大网站CSS初始化代码
  • css权重问题
  • CSS实现鼠标上移图标旋转效果
  • 使用CSS3制作一个简单的进度条(demo)
  • 用纯CSS实现饼状Loading等待图效果
  • 利用CSS3伪元素实现逐渐发光的方格边框
  • CSS3实现内凹圆角的实例代码
  • 利用HTML5+CSS3实现3D转换效果实例详解
  • css3+伪元素实现鼠标移入时下划线向两边展开的效果

相关文章

  • 2017-08-06图片的alt(替换文本)属性描述
  • 2017-08-06浅析CSS等高布局的6种方式
  • 2017-08-06CSS怎么将背景图左移/上移/右移10px
  • 2017-08-06CSS 网站性能优化笔记
  • 2017-08-06让Firefox未载入图片显示边框
  • 2017-08-06ie6不支持hover ie6 标签(除a标签)不支持伪类:hover解决方案
  • 2017-08-06CSS 新的图像替换方法
  • 2017-08-06CSS针对IE6实现网页图片底部留出空白的方法
  • 2017-08-06多列等高的CSS实现代码
  • 2017-08-06Div+Css实现屏蔽效果

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 关于Chrome浏览器字体显示的太小不一的bug处理
    • CSS3的media query学习攻略
    • css识别浏览器类型编写区分浏览器的代码
    • CSS实现三角效果的简单实例
    • firefox不显示border通过清除float便可解决
    • 使用CSS实现图片分割效果的简单方法介绍
    • DIV+CSS命名规范全记录
    • Discuz7.2 IE9兼容性写法 杜工完全修补方案
    • ie-css3.htc 让IE6, 7, and 8也支持box-shadow
    • CSS属性探秘系列(五):min-width

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有