css sticky footer经典布局的实现
建站知识 2021-07-03 07:55www.168986.cn长沙网站建设
什么是sticky footer布局?
我们常见的网页布局方式一般分为header(页头)部分,content(内容区)部分和footer(页脚)部分。当页头区和内容区的内容较少时,页脚区不是随着内容区排布而是始终显示在屏幕的最下方。当内容区的内容较多时,页脚能随着文档流撑开始终显示在页面的最下方。这就是传说中的Sticky footer布局。是不是很容易理解。不理解的小伙伴也没关系狼蚁网站SEO优化我就举个简单的例子。
一般指手机页面中,当内容高度撑不满一屏时,页脚紧贴屏幕底部;当内容高度超过一屏时,页脚紧随其后。
方法一flex弹性盒子布局
- 父容器container的display为flex,并规定项目排列顺序是纵向的
- content元素的flex为1,即有多余空间就增大
- footer定义一个高度
查看演示请狠狠地点击
<div class="container"> <div class="content">内容</div> <div class="footer">页脚</div> </div>
body { margin: 0; } .container { display: flex; flex-direction: column; min-height: 100vh; } .content { flex: 1; /非必须/ width: 100%; height: 300px; line-height: 300px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /非必须/ } .footer { height: 60px; /非必须/ width: 100%; line-height: 60px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /非必须/ }
方法二padding-bottom+负margin-
- 容器wrapper需要指定min-height为100vh(vh视窗高度)
- 内容写在content容器里,指定padding-bottom为footer容器的高度
- footer指定高度和margin-,并且margin-为高度的负值
查看演示请狠狠地点击
<div class="wrapper"> <div class="content">内容</div> </div> <div class="footer">页脚</div>
body { margin: 0; } .wrapper { width: 100%; min-height: 100vh; } .content { /padding-bottom应等于footer的高度/ padding-bottom: 60px; /非必须/ width: 100%; height: 400px; line-height: 400px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #71a8da; /非必须/ } .footer { /margin-应等于footer高度的负值/ margin-: -60px; height: 60px; /非必须/ width: 100%; line-height: 60px; text-align: center; color: #fff; font-size: 30px; font-weight: bold; background-color: #f85f2f; /非必须/ }
提示两个/非必须/
之间的部分不是实现sticky footer布局的必要代码,只是一些辅助样式,可以删除
到此这篇关于css sticky footer经典布局的实现的文章就介绍到这了,更多相关css sticky footer内容请搜索狼蚁SEO以前的文章或继续浏览狼蚁网站SEO优化的相关文章,希望大家以后多多支持狼蚁SEO!
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键