viewport-fit=cover适配iOS的webview时,body height: 100%;无法撑满整个屏幕;
解决方案:
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, shrink-to-fit=no, user-scalable=0, viewport-fit=cover"
/>
<style>
*{
padding: 0;
margin: 0;
}
html{
box-sizing: border-box;
width: 100%;
height: 100%;
background-color: red;
}
body{
box-sizing: border-box;
width: 100%;
/* 传统写法,无法适配iOS的全屏webview */
height: 100%;
background-color: blue;
/* 方案一:使用vh,vw,vh单位是相对于设备屏幕的,100vh可以撑满整个屏幕 */
height: 100vh;
/* 方案二:这个方案不好理解,但是能用 */
/* padding-top: 0 !important;
height: calc(96rpx + constant(safe-area-inset-bottom));
height: calc(96rpx + env(safe-area-inset-bottom)); */
}
.scroll-view{
width: 100%;
height: 100%;
overflow: auto;
background-color: yellow;
}
</style>