flex 实现移动端上下固定,中间滑动
如果你还在用position:fixed来保持移动端顶部、下部的导航栏在全局固定位置不动。
那你可以换种方法。更简单,方便,快捷;还不会受定位的影响。
不过注意,使用flex弹性布局的话,需要将设置flex的这个盒子所依赖的父标签的height有个固定的值,一般就是占满全局 height:100%;
。
大师兄飞速写完的flex移动端布局小栗子:
<!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,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>
<body>
<div class="app">
<div class="header"></div>
<div class="con">
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
<div class="temp">111</div>
</div>
<div class="footer"></div>
</div>
</body>
</html>
别说,还挺好看。
还没有评论,来说两句吧...