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>
相关推荐
讨厌吃蛋黄酥9 小时前
前端居中九种方式血泪史:面试官最爱问的送命题,我一次性整明白!
前端·css
意会10 小时前
微信闪照小程序实现
前端·css·微信小程序
码码哈哈爱分享11 小时前
Tauri 框架介绍
css·rust·vue·html
一枚前端小能手12 小时前
🎨 CSS布局从入门到放弃?Grid让你重新爱上布局
前端·css
落雪小轩韩13 小时前
网格布局 CSS Grid
前端·css
睡不着先生15 小时前
`text-wrap: balance` 实战指南:让多行标题自动排版更优美
css
Wcy307651906616 小时前
web前端第二次作业
前端·javascript·css
waterHBO16 小时前
css 模拟一个动画效果,消息堆叠。
前端·css
挽淚16 小时前
面试题:CSS 居中方案全解
css
老虎062717 小时前
JavaWeb前端(HTML,CSS具体案例)
前端·css·html