头尾固定,中间区域可以滑动效果是移动端最常见的效果,以京东页面为例。以前开发时常用的方法是用固定布局position:fixed;实现,但是该方法在ios上或者其他机型上会出现问题。现在,可以用flex方法快速实现该布局

<div class="wrap">       <div class="header">头部</div>       <div class="content">中间内容区域</div>       <div class="footer">尾部</div></div>
html,body{    height: 100%;    /* 很重要 */}.wrap{    width: 100%;    height: 100vh;     /* 很重要,如果设置成100%,页面内容过多时不会固定 */    display: flex;    flex-direction: column;    font-size: 16px;}.header{    background: aquamarine;    height: 60px;}.content{    flex: 1;    /* 很重要 */    overflow-y:auto; /* 很重要,否则当该内容超过一屏时,尾部区域不会固定 */    background: #4CAF50;}.footer{    background: tan;    height: 40px;}/* 让内容居中显示 */.header,.content,.footer{    display: flex;    align-items: center;    justify-content: center;}

运行效果:

说明:css样式中,一定要设置html,body以及最外层包裹容器的高度为100%,同时中间内容区域的样式一定要添加flex:1;以及overflow-y:auto;

©著作权归作者所有:来自51CTO博客作者wx605879fdc8dae的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 如何使用 Markdown and Emmet
  2. php 中文网 第十五期——第一课作业
  3. 文本文件内容查找 grep
  4. 静态 HTML 网页不能有动态内容吗?再考虑考虑!
  5. 第一篇:markdown和emmet语法详情
  6. 万岳知识付费系统更新内容 v 1.0.6
  7. Visual Studio Code 常用语法详解
  8. 015期开学第一课
  9. Markdown基本语法

随机推荐

  1. 我的Android进阶之旅------>Android视频
  2. Android maxLines maxLength属性
  3. 改变Android屏幕默认启动方向为横向
  4. android listview 设置点击效果selector
  5. How to root android emulator (Android
  6. Android 常用的画图方法
  7. Android中Sample的使用方法
  8. android 开发常用网站
  9. Android Application 之 allowBackup 属
  10. Android之获取Android唯一ID