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 小时前
前端物理引擎库推荐 - 让你的网页动起来!
前端
雾恋6 小时前
最近一年的感悟
前端·javascript·程序员
A黄俊辉A6 小时前
axios+ts封装
开发语言·前端·javascript
小李小李不讲道理7 小时前
「Ant Design 组件库探索」四:Input组件
前端·javascript·react.js
连合机器人7 小时前
晨曦中的守望者:当科技为景区赋予温度
java·前端·科技
郑板桥307 小时前
tua-body-scroll-lock踩坑记录
前端·javascript
BillKu8 小时前
vue3 样式 css、less、scss、sass 的说明
css·less·sass·scss
慢半拍iii8 小时前
JAVA Web —— A / 网页开发基础
前端
gnip9 小时前
pnpm 的 monorepo架构多包管理
前端·javascript
新手村领路人10 小时前
Firefox自定义备忘
前端·firefox