uni-app設置頁面背景及背景圖片


設置背景

1、設置背景色:
<template>
    <view class="container">  //最外層
          <view class="bg-set"></view>  //此標簽為最外層view標簽的第一個子標簽
          <view class="content"></view>
    </view> 
</template>

.bg-set{
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: #f4f4f4;
    z-index: -1;
}

2、設置背景圖
<template>
    <view class="container"> 
          <image class="bg-set" src="https://img-1258.file.myqcloud.com/bg.png"></image>
          <view class="content"></view>
    </view> 
</template>

.bg-set{
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
}

以上想法引自 https://www.cnblogs.com/swordLaughsHeaven/p/12118562.html 並略作修改

官網方式:

1、在 uni-app 中不能使用 * 選擇器。
2、page 相當於 body 節點,例如
<!-- 設置頁面背景顏色 -->
page {
  background-color:#ccc;
}



或者在globalSTyle中配置: https://uniapp.dcloud.io/collocation/pages?id=style

個人沒仔細研究,覺得局限還是有的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM