【问题标题】:How to solve the issue of position:fixed for a button at the bottom of the screen in iOS (ipad/iphone)?如何解决位置问题:iOS(ipad/iphone)屏幕底部的按钮固定?
【发布时间】:2019-03-18 06:29:42
【问题描述】:

我在屏幕底部有一个按钮。这是我的按钮的 CSS 样式:

.bottomfixed {
    width: 92%;
    display: block;
    height: 68px;
    border-radius: 6px;
    background-color: #f27d00;
    font-family: Helvetica-Bold, Arial;
    border: solid 0;
    outline: solid 12px #fff;
    font-size: 24px;
    color: #fff;
    margin: 0% 4% 0% 4%;
    position: fixed;
    bottom: 10px;
    left: 0;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    -ms-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}

如您所见,我设置了 position:fixed 按钮,但在 iOS(iPhone 和 iPad)中不起作用

我也有输入框。当我专注于这个输入框时,虚拟键盘在 iPhone 和 iPad 中打开,因为这个按钮被键盘重叠并且按钮的固定位置被忽略

不过,这在其他设备(如 android 手机)中运行良好。

那么如何使用 CSS 或 javascript 解决这个问题? (注:我的编程语言是PHP)

【问题讨论】:

    标签: ios css iphone ipad


    【解决方案1】:

    试试这个:

    .bottomfixed 
    {
       position:absolute;
       top:calc(100vh - (68px + 10px));
      /* 100 viewport height minus the height of the button and the height of the bottom position */
    }
    

    而不是这个:

    .bottomfixed 
    {
       position: fixed;
    }
    

    位置固定但未固定:https://codepen.io/carolmckayau/pen/qJXvGZ

    【讨论】:

    • 它似乎适用于除 iPad 和 iPhone 之外的所有设备
    • 胖胖的! grrr 位置如何:相对;而不是位置:绝对; ?
    猜你喜欢
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 2016-06-22
    • 2013-01-29
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多