How to use local pictures as mini program background

王林
Release: 2021-01-22 10:32:09
forward
2667 people have browsed it

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>
Copy after login

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;
}
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template