关于移动端position:fixedbug的解决方法

原因:移动端手机激活软键盘,fixed定位会出现元素位置漂移

解决办法:头部底部使用fixed定位,中间正文部分使用absolute,并设置top值和bottom值为顶部底部的高度。

具体代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />
<meta name="renderer" content="webkit">
<style type="text/css">
html{font-size: 40px;}
body{position: absolute;left: 0;width: 100%;height: 100%;overflow-x:hidden;margin: 0;font-size: .34rem;text-align: center;line-height: 3rem;color: #fff;}
.head,.footer{position: fixed;left: 0;background: #4d406b;height: .9rem;width: 100%;}
.head{top: 0;}
.content{position: absolute;left: 0;top: .9rem;bottom:.9rem;overflow-y:scroll;width: 100%;background-color: blue;}
.footer{bottom: 0;}
</style>
</head>
<body>
<div class="head"></div>
<div class="content">
    我是正文<br>我是正文<br>我是正文<br>我是正文<br>我是正文<br>我是正文<br>我是正文<br>我是正文<br>我是正文<br>
</div>
<div class="footer"></div>
</body>

</html>

 

posted @ 2016-07-30 11:45  亚飞啊  阅读(5937)  评论(0编辑  收藏  举报