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>
相关推荐
阿基米东6 小时前
从嵌入式到前端的探索之旅,分享 5 个开源 Web 小工具
前端·javascript·github
hxjhnct6 小时前
响应式布局有哪些?
前端·html·css3
LYFlied6 小时前
【每日算法】LeetCode215. 数组中的第K个最大元素
前端·算法
怎么就重名了6 小时前
Kivy的KV语言总结
前端·javascript·html
jqq6666 小时前
解析ElementPlus打包源码(四、打包主题)
前端·javascript·vue.js
代码猎人6 小时前
类数组对象是什么,如何转化为数组
前端
duanyuehuan6 小时前
js 解构赋值
开发语言·前端·javascript
进击的野人6 小时前
Vue3 响应式系统深度解析:从原理到实践
前端·vue.js·前端框架
计算机程序设计小李同学6 小时前
汽车4S店管理系统设计与实现
前端·spring boot·学习
SoraYama6 小时前
🚀 TypeScript 5.9:import defer 来袭
前端·typescript