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>
相关推荐
废嘉在线抓狂.1 分钟前
简易拆开即用的高性能计时器(C#)
前端·unity·c#
yuguo.im5 分钟前
91 行代码实现一个打飞机游戏(HTML5 Canvas 版)
前端·游戏·html5·打飞机
怪侠_岭南一只猿11 分钟前
爬虫工程师学习路径 · 阶段四:反爬虫对抗(完整学习文档)
css·爬虫·python·学习·html
从文处安26 分钟前
「前端何去何从」一直写 Vue ,为何要在 AI 时代去学 React「2」?
前端·react.js
掘金者阿豪27 分钟前
深入解读OpenClaw配置文件:一个现代化AI网关的全景洞察
前端
葡萄城技术团队28 分钟前
Playwright 官方推荐的 Fixture 模式,为什么大厂架构师却在偷偷弃用?
前端
newbe3652429 分钟前
ImgBin CLI 工具设计:HagiCode 图片资产管理方案
前端·后端
bluceli31 分钟前
CSS Scroll Snap:打造丝滑滚动体验的利器
前端·css
www_stdio33 分钟前
深入理解 React Fiber 与浏览器事件循环:从性能瓶颈到调度机制
前端·react.js·面试
工边页字38 分钟前
LLM 系统设计核心:为什么必须压缩上下文?有哪些工程策略
前端·人工智能·后端