一、media query方式
/*iPhone X 適配*/ @media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) { .fixed-bottom{ bottom: 37px; } } /*iPhone XS max 適配*/ @media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio:3) { .fixed-bottom{ bottom: 37px; } } /*iPhone XR max 適配*/ @media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio:2) { .fixed-bottom{ bottom: 37px; } }
存在的問(wèn)題:在微信webveiw內(nèi)部此方案能在元素底部加上安全區(qū)域?qū)挾龋瑳](méi)有問(wèn)題。但是在safari等有底欄的瀏覽器(頁(yè)面顯示區(qū)域已經(jīng)在安全區(qū)內(nèi)部)也同樣會(huì)加上安全區(qū)寬度。
(視頻教程:css視頻教程)
二、CSS函數(shù)
蘋果在推出全面屏之后提供的CSS函數(shù),ios<11.2為constant(),ios>11.2為env()??商钊雜afe-area-inset-top、safe-area-inset-left、safe-area-inset-right、safe-area-inset-bottom對(duì)應(yīng)上下左右的安全區(qū)域?qū)挾取nv 和 constant 只有在 viewport-fit=cover 時(shí)候才能生效。
代碼如下:
meta標(biāo)簽加入viewport-fit=cover
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
css寫法,不支持env、constant的瀏覽器會(huì)忽略此樣式
.fixed-bottom{ bottom: 0; bottom: constant(safe-area-inset-bottom); bottom: env(safe-area-inset-bottom); }
推薦教程:CSS入門基礎(chǔ)教程
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com