css基础:底部固定,导航栏浮动在顶部

场景:底部浮动在底部,导致栏如果下面内容过长浮动在顶部,用到的是position:sticky

一、方法一

javascript 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <style>
    body {
      margin: 0;
      padding: 0;
    }
    .detail {
      width: 100%;
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: auto;
    }
    .header {
      background-color: pink;
      width: 100%;
      height: 200px;
      padding: 12px 24px;
      box-sizing: border-box;
    }
    .tabs {
      position: sticky;
      top: 0;
      height: 32px;
      line-height: 32px;
      background: yellow;
      border-radius: 8px;
      padding-left: 30px;
      display: flex;
      align-items: center;
      z-index: 9;
    }
    .tabContent {
      flex: 1;
      background: orange;
    }
    .box {
      height: 1000px;
      border: 2px solid red;
    }
    .footer {
      position: sticky;
      width: 100%;
      background: gray;
      padding: 16px;
      box-sizing: border-box;
      bottom: 0;
      z-index: 10;
      display: flex;
      flex-direction: column;
    }
  </style>
  <body>
    <div class="detail">
      <div class="header">头部</div>
      <div class="tabs">tabs内容</div>
      <div class="tabContent">
        <div class="box">这是里内容模块</div>
      </div>
      <div class="footer">底部</div>
    </div>
  </body>
</html>
相关推荐
沙蒿同学3 小时前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github
变与不变8064 小时前
jQuery细节以及使用应用场景
前端·javascript·jquery
SailingCoder5 小时前
【封闭结束1】端到端交付:Agent 一次请求如何走完全链路
前端·安全·ai·面试·agent·harness
风骏时光牛马7 小时前
AI多模块协同自动化工作流
前端
zhangminghuan8 小时前
前端面试应对技巧
前端·面试·职场和发展
计算机魔术师8 小时前
潜伏14年的PHP致命洞,AI跑两天就交卷了
前端
IT_陈寒8 小时前
Vue的这个响应式陷阱我居然现在才发现
前端·人工智能·后端
Python自动化直播9 小时前
智能脚本批量管理拆开看:导入、导出、重写、试听
前端·python·ai·秒播
开开心心就好9 小时前
发票信息录入太麻烦?离线工具一键转表格
运维·服务器·前端·pdf·ocr·maven·intellij-idea