- 设置viewport-fit=cover
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
- 设置安全区域
.u-safeAreaInset-top {
height: constant(safe-area-inset-top) !important;
height: env(safe-area-inset-top) !important;
}
.u-safeAreaInset-bottom {
height: constant(safe-area-inset-bottom) !important;
height: env(safe-area-inset-bottom) !important;
}
- 实例如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
<title>Document</title>
<style>
.u-safeAreaInset-top {
height: constant(safe-area-inset-top) !important;
height: env(safe-area-inset-top) !important;
}
.u-safeAreaInset-bottom {
height: constant(safe-area-inset-bottom) !important;
height: env(safe-area-inset-bottom) !important;
}
html, body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.container {
width: 100vw;
height: 100vh;
overflow: hidden;
box-sizing: border-box;
padding-bottom: 12vw;
background-color: bisque;
position: relative;
}
.body {
width: 100%;
height: 100%;
overflow-y: auto;
}
.content {
height: 3000px;
background-color: chocolate;
}
.footer {
position: fixed;
width: 100%;
height: 12vw;
left: 0;
bottom: 0;
background-color: #369;
}
</style>
</head>
<body>
<div class="container">
<div class="body">
<div class="content"></div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
如需局部使用,如下
.safeAreaTop {
padding-top: constant(safe-area-inset-top);
padding-top: env(safe-area-inset-top);
}
.safeAreaBottom {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}