解决IOS移动端固定定位失效问题

根据浏览器窗口position:fixed; 定位在底部的元素,会随着屏幕的滚动而滚动,在iOS系统上不起作用。

<div class="header">头部</div>
 
<div class="main">
      <div class="content">
           <!-- 可以滚动的区域 -->
      </div>
</div>
 
<footer class="footer"> 
        <!-- fixed定位的底部 -->
        <input type="text" placeholder="请输入姓名">
</footer>
     .header {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 100px;
        }
 
        .footer {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 30px;
        }
 
        .main {
            /*main绝对定位,进行内部滚动*/
            position: absolute;
            /*top是头部的高度*/
            top: 100px;
            /*bottom是底部的高度*/
            bottom: 30px;
            /*使之可以滚动*/
            overflow-y: scroll;
            /*增加弹性滚动,解决滚动不流畅的问题*/
            -webkit-overflow-scrolling: touch;

        }    

猜你喜欢

转载自www.cnblogs.com/theblogs/p/10495029.html