iphoneX之Html5適配

好好的運(yùn)行了一年多的H5網(wǎng)頁,今天突然QA同學(xué)拿著個iphoneX過來,說得適配一波。
一看是iphoneX的齊劉海擋住了UI頂部的一個經(jīng)驗條。那就改一波吧。公司項目不方便放圖。

想了好久,不想大改UI,只想將被齊劉海遮住的經(jīng)驗條下移。想到了使用css偽元素。偽元素作為一個裝飾在html頭部插入一個空白間距。方法如下

新建一個css文件:iphoneX.css
@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
  /*增加頭部適配層*/
  .html-topbar {
    height: 100%;
    box-sizing: border-box;
    padding-top: 44px;
    &:before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 44px;
        background-color: #000000;
        z-index: 9998;
    }
  }
}

注釋&:before是一種簡寫方式,等價為.html-topbar:before,另外偽元素的content不可省略(哪怕內(nèi)容為空),否則偽元素不執(zhí)行。

在原h(huán)tml中加入css,并未html標(biāo)簽設(shè)置類名
<html class="html-topbar">
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
<link rel="stylesheet" type="text/css" href="iphoneX.css">

加入后有效,以后針對特定手機(jī)屏幕適配也可以使用@media only screen and (device-width: 375px) and (device-height: 812px)這種方式。

擴(kuò)展閱讀:大放異彩的偽元素

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容