本篇文章小编给大家分享一下css sticky footer经典布局实现代码,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
什么是sticky footer布局?
我们常见的网页布局方式一般分为header(页头)部分,content(内容区)部分和footer(页脚)部分。当页头区和内容区的内容较少时,页脚区不是随着内容区排布而是始终显示在屏幕的最下方。当内容区的内容较多时,页脚能随着文档流撑开始终显示在页面的最下方。这就是传说中的Sticky footer布局。
一般指手机页面中,当内容高度撑不满一屏时,页脚紧贴屏幕底部;当内容高度超过一屏时,页脚紧随其后。
方法一:flex弹性盒子布局
父容器container的display为flex,并规定项目排列顺序是纵向的
content元素的flex为1,即有多余空间就增大
footer定义一个高度
查看演示请狠狠地点击:flex弹性盒子布局实现sticky footer
内容
body { margin: 0; } .container { display: flex; flex-direction: column; min-height: 100vh; } .content { flex: 1; /*非必须*/ width: 100%; line- text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /*非必须*/ } .footer { /*非必须*/ width: 100%; line- text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /*非必须*/ }
方法二:padding-bottom+负margin-top
容器wrapper需要指定min-height为100vh(vh:视窗高度)
内容写在content容器里,指定padding-bottom为footer容器的高度
footer指定高度和margin-top,并且margin-top为高度的负值
查看演示请狠狠地点击:padding-bottom+负margin-top实现sticky footer
内容
body { margin: 0; } .wrapper { width: 100%; min-height: 100vh; } .content { /*padding-bottom应等于footer的高度*/ padding-bottom: 60px; /*非必须*/ width: 100%; line- text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /*非必须*/ } .footer { /*margin-top应等于footer高度的负值*/ margin-top: -60px; /*非必须*/ width: 100%; line- text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /*非必须*/ }
提示:两个/**非必须**/之间的部分不是实现sticky footer布局的必要代码,只是一些辅助样式,可以删除。
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级