flex 实现移动端上下固定,中间滑动

淩亂°似流年 2023-03-04 06:37 56阅读 0赞

如果你还在用position:fixed来保持移动端顶部、下部的导航栏在全局固定位置不动。

那你可以换种方法。更简单,方便,快捷;还不会受定位的影响。

不过注意,使用flex弹性布局的话,需要将设置flex的这个盒子所依赖的父标签的height有个固定的值,一般就是占满全局 height:100%;

大师兄飞速写完的flex移动端布局小栗子:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <style> body,html{ height: 100%; width: 100%; margin: 0; padding: 0; } .app{ height: 100%; width: 100%; display: flex; flex-direction: column; } .header{ height: 40px; background-color: orange; } .con{ background: aqua; overflow: auto; flex: 1; } .temp{ height: 200px; background: cornflowerblue; margin: 10px; } .footer{ background: blue; height: 50px; } </style>
  9. <body>
  10. <div class="app">
  11. <div class="header"></div>
  12. <div class="con">
  13. <div class="temp">111</div>
  14. <div class="temp">111</div>
  15. <div class="temp">111</div>
  16. <div class="temp">111</div>
  17. <div class="temp">111</div>
  18. <div class="temp">111</div>
  19. <div class="temp">111</div>
  20. <div class="temp">111</div>
  21. </div>
  22. <div class="footer"></div>
  23. </div>
  24. </body>
  25. </html>

在这里插入图片描述

别说,还挺好看。

发表评论

表情:
评论列表 (有 0 条评论,56人围观)

还没有评论,来说两句吧...

相关阅读

    相关 移动滑动

    前言 移动端,滑动是很常见的需求。很多同学都用过[swiper.js][],本文从原理出发,实践出一个类swiper的滑动小插件[ice-skating][]。 小插件