解决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;

        }    

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM