標籤:
原因:移動端手機啟用軟鍵盤,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>
關於移動端position:fixedbug的解決方案