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>
相关推荐
请叫我欧皇i4 分钟前
免费开源!Vue2 + OpenStreetMap 打造动态地图:标记点与弹窗高级定制
前端·vue.js·开源
亚洲小炫风13 分钟前
React 分页轻量化封装
前端·react.js·前端框架
yilan_n13 分钟前
【UniApp实战】手撸面包屑导航与路由管理 (拒绝页面闪烁)
前端·javascript·vue.js·uni-app·gitcode
TG:@yunlaoda360 云老大15 分钟前
腾讯云国际站代理商 CSS有什么优势呢?
css·云计算·腾讯云
lang2015092816 分钟前
深入解析Sentinel熔断机制
java·前端·sentinel
Highcharts.js23 分钟前
官方文档|Vue 集成 Highcharts Dashboards
前端·javascript·vue.js·技术文档·highcharts·看板·dashboards
Misha韩26 分钟前
vue3+vite模块联邦 ----子应用中页面如何跳转传参
前端·javascript·vue.js·微前端·模块联邦
开发者小天28 分钟前
react中的使用useReducer和Context实现todolist
前端·javascript·react.js
Youyzq29 分钟前
react-inlinesvg如何动态的修改颜色SVG
前端·react.js·前端框架
wniuniu_30 分钟前
rbd创建特定的用户
前端·chrome