小程序全面屏適配

basic.less(全局樣式)中:

page {

  // height: 100%; // 不要加 height: 100%;

  padding-bottom: constant(safe-area-inset-bottom); // 適配全面屏

  padding-bottom: env(safe-area-inset-bottom);

}

// 如果頁面底部有固定button,高度為120rpx,加此下代碼

.has-button-padding {

  padding-bottom: 120rpx !important;

}

頁面底部button組件bottomButton:

<view class="bottomButton"></view>
  .bottomButton {

    position: fixed;

    bottom: 0;

    width: 100%;

    height: 120rpx;

    padding-bottom: constant(safe-area-inset-bottom);

    padding-bottom: env(safe-area-inset-bottom);

  }

如果頁面內(nèi)容不限制高度,則正常添加如上適配就行。如果限制一屏高度,如下圖:

CE9CEB8E-B626-4A9A-B7C0-DBDA5B7E5313.png
<div class="crm-other-container has-button-padding">

  <van-tree-select items="{{ infoItems }}" main-active-index="{{ mainActiveIndex }}" active-id="{{ activeId }}"          bind:clicknav="onClickNav" bind:clickitem="onClickItem" />

  <bottomButton btnArr="{{ btnArr }}" />

  <van-toast id="van-toast" />

</div>
<style lang="less">

  .crm-other-container {

    box-sizing: border-box;

    height: 100%;

  .van-tree-select {

    height: calc(100vh - 120rpx - constant(safe-area-inset-bottom)) !important;

    height: calc(100vh - 120rpx - env(safe-area-inset-bottom)) !important;

    overflow-y: auto; // 屬性規(guī)定是否對內(nèi)容的上/下邊緣進(jìn)行裁剪 - 如果溢出元素內(nèi)容區(qū)域的話,則提供滾動(dòng)機(jī)制

  }

}
</style>
關(guān)于height:100%和height:100vh的區(qū)別

vh就是當(dāng)前屏幕可見高度的1%,也就是說

height:100vh == height:100%;

但是當(dāng)元素沒有內(nèi)容時(shí)候,設(shè)置height:100%,該元素不會(huì)被撐開,此時(shí)高度為0,

但是設(shè)置height:100vh,該元素會(huì)被撐開屏幕高度一致。

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

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

  • 前言 微信小程序(以下簡稱小程序)的自定義導(dǎo)航欄樣式已經(jīng)開放很久了,一直也沒深入的研究過。前段時(shí)間時(shí)間看到Read...
    快抓住那個(gè)胖子閱讀 8,659評論 1 4
  • 每天的學(xué)習(xí)記錄,可能有的地方寫的不對,因?yàn)閯倢W(xué),以后發(fā)現(xiàn)錯(cuò)的話會(huì)回來改掉整體流程 https://develope...
    有點(diǎn)健忘閱讀 5,026評論 0 7
  • @(概述)[基本概念|百分比|rem|vw/vh|響應(yīng)式設(shè)計(jì)] 移動(dòng)端web頁面的開發(fā),由于手機(jī)屏幕尺寸、分辨率不...
    jluemmmm閱讀 77,975評論 1 42
  • 眾所周知,移動(dòng)端適配的問題一個(gè)長期且艱巨的任務(wù)。市面上的適配方案也是五花八門,而且在不斷的更新。但是大部分的方案依...
    程愷閱讀 743評論 0 0
  • 微信小程序開發(fā)01 1、從0開發(fā)helloworld 從0開發(fā)hello,world,初始化一個(gè)項(xiàng)目,基本架構(gòu)只留...
    Juntech閱讀 251評論 0 0

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