小程序 · 2024年2月27日

微信小程序怎样加背景图片

经常为小程序设置颜色背景,突然发现一张好看的图片怎么把它设置为背景呢?

微信小程序怎样加背景图片    

以下总结了三种方法:

1、wxss中通过background-image设置网络图片来添加背景图片

微信小程序中background-image不能使用本地图片

推荐学习:

background-image:url(https://xxxxxxxxxxxxxxxxxxxxxx)

登录后复制

2、将图片转为Base64编码格式,然后使用background-image来添加背景图片;

background-image:url(转换之后的base64字符串)

登录后复制

3、利用流布局,设置z-index层级,将image标签置于底层来添加背景图片。

//html
<view>
  <image></image>
  <view>
    我是一串字符串
  </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;
}

登录后复制

PHP中文网,大量,欢迎学习!

以上就是小程序怎样加背景图片的详细内容,更多请关注GTHOST其它相关文章!