关于移动端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>

 

转载于:https://www.cnblogs.com/wyf1992/p/5720611.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值