首頁  >  文章  >  微信小程式  >  微信小程式背景圖片顯示不出來

微信小程式背景圖片顯示不出來

尚
原創
2020-03-26 15:55:547392瀏覽

微信小程式背景圖片顯示不出來

開發小程式的時候,設定頁面的背景,用到css程式碼:

.page__bd{
    width: 100%;
    height: 220px;
    background: url('../../assets/img/images.jpg') no-repeat;
    background-size: 100% 100%;
}

在偵錯工具上是顯示的,但是掃面上傳到手機上卻顯示不出來。

這是由於:background-image 只能用網路url或base64圖片編碼 , 本地圖片只能用 image標籤src屬性才行。當然 image標籤src屬性也可以使用網路url或base64圖片編碼。

解決方法:

下面透過image 標籤src屬性設置,實現背景圖顯示

介面結構:

<view class=&#39;set-background&#39;>
    <image class=&#39;background-image&#39; src=&#39;{{item.countryPic}}&#39;></image>
    <view class=&#39;background-content&#39;>
        <view class="set-background-avatar" background-size="cover">
            <image class="post-specific-image" src="{{item.picture}}"></image>
        </view>
    </view>
</view>

wxss樣式:  

.set-background {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 150px;
}
.set-background-avatar {
    width: 220px;
    height: 150px;
}
.background-content {
    position: absolute;
    z-index: 1;
}
.background-image {
    width: 225px;
    height: 150px;
    opacity: 0.8;
}
.post-specific-image {
    width: 215px;
    height: 150px;
    vertical-align: middle;
}

推薦:《小程式開發教學

以上是微信小程式背景圖片顯示不出來的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn