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>
相关推荐
千码君201610 小时前
React Native:关于react自定义css属性的位置
css·react native·react.js·前端框架·ecmascript·组件嵌套
超级大只老咪12 小时前
字段行居中(HTML基础语法)
前端·css·html
三月暖阳12 小时前
分享并记录日常开发中的一些CSS布局和样式技巧(持续更新)
css·scss
汤姆Tom14 小时前
现代 CSS 架构与组件化:构建可扩展的样式系统
前端·css
汤姆Tom14 小时前
CSS 最佳实践与规范
前端·css
志摩凛14 小时前
前端必备技能:使用 appearance: none 实现完美自定义表单控件
前端·css
我有一棵树15 小时前
浏览器/用户代理默认样式、any-link 伪类选择器
前端·css·html
西洼工作室1 天前
浏览器事件循环与内存管理可视化
前端·javascript·css·css3
软件技术NINI1 天前
html css js网页制作成品——化妆品html+css+js (7页)附源码
javascript·css·html
前端Hardy1 天前
HTML&CSS:一眼心动的 SVG 时钟
前端·javascript·css