Home >WeChat Applet >Mini Program Development >How to use local pictures as mini program background

How to use local pictures as mini program background

王林
王林forward
2021-01-22 10:32:092722browse

How to use local pictures as mini program background

We know that you cannot directly set local images for views in WeChat mini programs. So how do we solve this problem?

(Learning video sharing: Introduction to Programming)

The solution is as follows:

1. Use network pictures

2. Use base64 format

3. Use image to load local pictures, and then use them as interface backgrounds

The first two are very simple, let’s focus on the third one below. Generally, everyone's trouble is to put the imageview at the bottom of the interface. Then go directly to the code below.
wxml

<view class="root">
  <image class=&#39;background-image&#39; src=&#39;../res/login_bg.png&#39; mode="aspectFill"></image>
  <view class="content">
  </view>
</view>

wxss

.root {
   width: 100%;
    height: 100%;
    background-color: #70c7da;
    position: relative;
}

.background-image{
   height : 100%;
    position: absolute;
    width: 100%;
    left: 0px;
    top: 0px;
}
.content{
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0px;
    top: 0px;
}

Okay, done. As long as you use relative layout, you can achieve it. Similar to android relative layout. Now just write all the content in content

Related recommendations:小program development tutorial

The above is the detailed content of How to use local pictures as mini program background. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete