zoukankan      html  css  js  c++  java
  • 移动端CSS底部固定和fixed定位在ios上的bug

    fixed定位在ios上的bug

    假设我们页面的 HTML 结构是这样:

     <div class="wrapper">
        <div class="content"><!-- 页面主体内容区域 --></div>
        <div class="footer"><!-- 需要做到 Sticky Footer 效果的页脚 --></div>
    </div>
    

    方法1.:absolute

    通过绝对定位处理应该是常见的方案,只要使得页脚一直定位在主容器预留占位位置。

     html, body {
        height: 100%;
    }
    .wrapper {
        position: relative;
        min-height: 100%;
        padding-bottom: 50px;
        box-sizing: border-box;
    }
    .footer {
        position: absolute;
        bottom: 0;
        height: 50px;
    }
    
    

    这个方案需指定 html、body 100% 的高度,且 content 的 padding-bottom 需要与 footer 的 height 一致。

    方法2:增加同级占位符

        <div>
            <div style="height:60px;">占位符(ps:假定footer高60px)</div>
            <section class="footer">
                <input type="button" value="确认添加"/>
            </section>
        </div>
    

    方法3:通过计算函数 calc 计算(视窗高度 - 页脚高度)赋予内容区最小高度,不需要任何额外样式处理,代码量最少、最简单。

      .content {
        min-height: calc(100vh - 50px);
    }
    .footer {
        height: 50px;
    }
    
    

    如果不需考虑 calc() 以及 vh 单位的兼容情况,这是个很理想的实现方案。
    同样的问题是 footer 的高度值需要与 content 其中的计算值一致。

    方法4:Flexbox

    Flexbox 是非常适合实现这种效果的,使用 Flexbox 实现不仅不需要任何额外的元素,而且允许页脚的高度是可变的。

    虽然大多数 Flexbox 布局常用于水平方向布局,但别忘了实际上它也可用于垂直布局,所以你需要做的是将垂直部分包装在一个 Flex 容器中,并选择要扩展的部分,他们将自动占用其容器中的所有可用空间。

      html {
        height: 100%;
    }
    body {
        min-height: 100%;
        display: flex;
        flex-direction: column;
    }
    .content {
        flex: 1;
    }
    
    

    需要注意的是想要兼容各种系统设备,需要兼顾 flex 的兼容写法。

  • 相关阅读:
    DataGrid内容导出Excel文件(C#)
    IE无法查看源文件原因及解决办法
    通过Internet访问内网中的服务器
    工欲善其事,必先利其器——图文并茂详解VisualStudio使用技巧
    Flash中对动态文本框使用遮罩
    Flash中XML跨域访问数据的规则
    Google导航代码
    信息竞赛小结
    第一天,开始系统学习 void
    浅析各种数据类型的取值范围 void
  • 原文地址:https://www.cnblogs.com/Lewiskycc/p/6944391.html
Copyright © 2011-2022 走看看