美文网首页
移动端常用布局1-头部、底部固定,内容滚动

移动端常用布局1-头部、底部固定,内容滚动

作者: gitJason | 来源:发表于2021-05-18 13:52 被阅读0次

移动端常用布局

  • 头部、底部固定,内容滚动。效果如下图:
  • 实现原理:
    • 头部、内容、底部为同一层级,头部、底部子级元素添加固定定位fixed
    • 给一个空标签设置高度,解决fixed定位后导航栏遮盖内容的问题或者给父级标签设置高度
clipboard.png
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>移动端常用布局</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      background-color: #f7f8fa;
    }
    .nav {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      z-index: 99;
      line-height: 56px; /* 这里也需要添加高度 */
      background-color: #fff;
      border-bottom: 1px solid #eee;
      text-align: center;
    }
    /* 给一个空标签设置高度,解决fixed定位后导航栏遮盖内容的问题 */
    .nav-placeholder {
      height: 56px;
    }
    section {
      background-color: #fff;
      margin: 10px 0;
    }
    .cell {
      padding: 10px 16px;
      border-bottom: 1px solid #eee;
    }
    .footer-nav {
      position: fixed;
      left: 0;
      bottom: 0;
      right: 0;
      z-index: 99;
      line-height: 56px;
      background-color: #fff;
      border-top: 1px solid #eee;
      display: flex;
    }
    .footer-nav div {
      flex: 1;
      text-align: center;
    }
  </style>
</head>
<body>
  <header>
    <!-- 固定定位 -->
    <div class="nav">头部</div>
    <!-- 给一个空标签设置高度,解决fixed定位后导航栏遮盖内容的问题 或者 给 header 标签设置高度 -->
    <div class="nav-placeholder"></div>
  </header>
  <section>
    <div class="cell">Content-start</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content</div>
    <div class="cell">Content-end</div>
  </section>
  <footer>
    <div class="footer-nav">
      <div>首页</div>
      <div>分类</div>
      <div>我的</div>
    </div>
    <div class="nav-placeholder"></div>
  </footer>
</body>
</html>

相关文章

  • 移动端常用布局1-头部、底部固定,内容滚动

    移动端常用布局 头部、底部固定,内容滚动。效果如下图: 实现原理:头部、内容、底部为同一层级,头部、底部子级元素添...

  • 记 微信 H5 开发

    一、页面布局问题模拟移动端页面,大体布局思路是,头部区域,中间内容区域,底部区域大体结构: 头部 中间内...

  • 2019-11-21

    界面整体布局(固定头部,底部)

  • 逻辑思维

    技术栈有哪些 写一个头部固定,左侧边栏固定,右边内容自适应的布局,请给出多种写法 平时PC端和移动端哪个接触的多 ...

  • flex布局

    移动端布局通常会制作头部的导航和底部的菜单,如果使用flex布局会非常简单,这里简单做个记录。/css/base....

  • 在Bootstrap框架下实现固定页脚

    固定在窗口底部 不会随内容滚动而消失。 固定在页面底部 粘在内容底部,内容未撑满窗口时则粘在窗口底部。 参考 ht...

  • 头部固定内容滚动的方法

    利用flex布局和overflow-x样式可以简单的实现头部导航固定不动,内容区域滚动的效果。 .page{ d...

  • 仿写京东移动端首页

    一、项目简介 该项目是制作京东移动端页面,完成首页头部搜索和底部导航布局,利用 swiper 完成首页的轮播图效果...

  • stick footer布局

    在手机端网页中常常会遇到这种布局需求:将footer固定到底部。文章内容不足满屏时 footer在底部,超过满屏时...

  • js,jq获取屏幕各种宽高尺寸

    js jq 检测window滚动到屏幕头部底部 检测div滚动到屏幕头部底部 解绑滚动监听 参考博文:JS,Jqu...

网友评论

      本文标题:移动端常用布局1-头部、底部固定,内容滚动

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