• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

iPhoneX底部安全区域适配

武飞扬头像
phyark
帮助1

问题

H5 手机底部和黑线重叠不美观

解决方法

通过viewport constant(safe-area-inset-bottom) env(safe-area-inset-bottom) 来为iphoneX底部的黑线做底部安全区适配

步骤 1

找到 name = viewportmeta 标签并 追加 viewport-fit=cover

  <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover">

步骤 2

为需要适配安全区域的类添加以下兼容样式

.safe-area {
	padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/
	padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
}

案例

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <!-- 以下mete标签需要加上 viewport-fit=cover -->
  <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover">
  <title>Document</title>
  <style>
    .nav-bar {
      width: 100%;
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      background: #f1f1f1;
      display: flex;
      justify-content: space-between;

      /* 以下顺序不能变 */
      /*兼容 IOS<11.2*/
      /* padding-bottom: constant(safe-area-inset-bottom); */
      /*兼容 IOS>11.2*/
      /* padding-bottom: env(safe-area-inset-bottom); */
    }

    .nav-bar-item {
      height: 60px;
      width: calc(100vw / 4);
      line-height: 60px;
      text-align: center;
    }
  </style>
</head>

<body>
  <h1>iphoneX底部安全区域适配</h1>
  <nav class="nav-bar">
    <span class="nav-bar-item">首页</span>
    <span class="nav-bar-item">关注</span>
    <span class="nav-bar-item">搜索</span>
    <span class="nav-bar-item">我的</span>
    <nav>
</body>

</html>
学新通

效果

学新通

学新通

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhhaecah
系列文章
更多 icon
同类精品
更多 icon
继续加载