ios底部小横条高度适配

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, viewport-fit=cover">
    <title>ios底部小横条高度适配</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            background-color: pink;
        }

        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            position: fixed !important;
            width: 100vw;
            height: 50px;
            z-index: 100;
            background-color: blue;
            bottom: constant(safe-area-inset-bottom) !important; /* 兼容 iOS < 11.2 */
            bottom: env(safe-area-inset-bottom) !important; /*兼容 IOS >= 11.2*/
        }

        .bottom {
            display: flex;
            justify-content: center;
            align-items: center;
            position: fixed !important;
            bottom: 0;
            background-color: red;
            width: 100vw;
            height: constant(safe-area-inset-bottom) !important;
            height: env(safe-area-inset-bottom) !important;
        }
    </style>
    <script>
        // 使用js去设置meta标签(本人在做海报项目时是直接把下面属性写到meta标签中的,但是没效果,放到这个js里面动态设置就好了,海报项目是vue3+vite)
        // 在当前示例里面,注释掉下面的js也没问题,具体原因未知,如果各位设置meta没效果的话可以尝试一下这个属性
        (document.getElementsByName('viewport')[0]).content =
            'user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, viewport-fit=cover';
    </script>
</head>

<body>
    <div class="container"> 我是内容区域 </div>
    <div class="bottom">我是距离底部的高度模块</div>
</body>

</html>
相关推荐
韩曙亮1 小时前
【Web APIs】元素偏移量 offset 系列属性 ④ ( offset 属性案例 - 放大镜效果 )
前端·javascript·css·html·offset·dom·web apis
相逢一笑与君行2 小时前
css使用grid布局实现网格(表格),动态调整行高,列宽,整体缩放,插入行,列,删除行,列
前端·css·react
韩曙亮2 小时前
【Web APIs】元素可视区 client 系列属性 ( client 属性简介 | 常用的 client 属性 | 使用场景 | 代码示例 )
前端·javascript·css·css3·bom·client·web apis
冰暮流星21 小时前
css3网格布局2
前端·css·css3
沐风。561 天前
css函数
前端·css·css3
沐风。561 天前
通过js动态更新css变量
javascript·css·tensorflow
BD_Marathon1 天前
【JavaWeb】CSS_三种引入方式
前端·css
Hy行者勇哥1 天前
HTML5 + 原生 CSS + 原生 JS 网页实现攻略
javascript·css·html5
小王码农记2 天前
CSS中自定义属性函数var()
前端·css·vue.js
BD_Marathon2 天前
【JavaWeb】CSS浮动
前端·css