經(jīng)常為微信小程序設(shè)置顏色背景逝变,突然發(fā)現(xiàn)一張好看的圖片怎么把它設(shè)置為背景呢?
以下總結(jié)了三種方法:
css中通過(guò)url獲取網(wǎng)絡(luò)圖片
微信小程序中不能使用本地圖片
background-image:url(https://xxxxxxxxxxxxxxxxxxxxxx)
Base64編碼格式
background-image:url(轉(zhuǎn)換之后的base64字符串)
利用流布局岂津,設(shè)置z-index層級(jí),將image標(biāo)簽置于底層
//html
<view class="container">
<image src='../image/1.jpg'></image>
<view class='up'>
我是一串字符串
</view>
</view>
//css
.container{
width: 100%;
height: 600rpx;
margin: 0;
padding: 0;
position: relative;
}
image{
position: absolute;
width: 100%;
height: 600rpx;
}
.up{
position: absolute;
z-index: 1;
}