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>
相关推荐
哈里谢顿12 小时前
CSS 入门完全指南:从零构建你的第一个样式表
css
. . . . .12 小时前
CSS 编写与管理范式 - Tailwind和CSS-in-JS
css
RFCEO1 天前
前端编程 课程十六、:CSS 盒子模型
css·前端基础课程·css盒子模型·css盒子模型的组成·精准控制元素的大小和位置·css布局的基石·内边距(padding)
夏幻灵2 天前
CSS三大特性:层叠、继承与优先级解析
前端·css
会编程的土豆2 天前
新手前端小细节
前端·css·html·项目
珹洺2 天前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
BillKu2 天前
VS Code HTML CSS Support 插件详解
前端·css·html
1024小神3 天前
用css的clip-path裁剪不规则形状的图片展示
前端·css
GGGG寄了3 天前
CSS——文字控制属性
前端·javascript·css·html
HWL56793 天前
在网页中实现WebM格式视频自动循环播放
前端·css·html·excel·音视频