As mobile application development becomes more and more popular, the development of cross-platform mobile applications has gradually become a trend. As a cross-platform development tool, UniApp’s advantages are self-evident. In the development of UniApp, it is often necessary to set a background image to beautify the page and allow users to better use the application. So, how does UniApp put a background image on a page? Let’s discuss it together.
First, we need to prepare a background image, which can be a solid color image or a pattern background image. Then, we can choose to add a style where the view tag is used to set the background image. For example:
\
In this way, we need to add the .bg class in the style file, as follows:
.bg{
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
Here, what we need to pay attention to is that the image path needs Use relative paths or absolute paths. UniApp’s default image path is /static/. At the same time, we need to set the size and position of the image. Here we use the cover attribute and center attribute.
If we need to set a full-screen background image, then we can add the following code to the uni.scss file:
page{
height: 100%;
.bg {
position: absolute; top:0; left: 0; right: 0; bottom: 0;
}
}
Here we use the position attribute to set the position of the element, and determine the position occupied by the element through the top, left, right, and bottom attributes. Finally, the effect of full-screen display is achieved.
Of course, we can also define the global background image through uni-app-preview. The specific method is as follows:
Add the following code to the style tag in the App.vue file:
background-image:url("/static/images/bg.jpg"); background-repeat: no-repeat; background-size: cover; background-position: center center;
}
With this method, we only need to define it in the App.vue file to set the global background image.
In short, UniApp has many ways to set background images, and we need to choose according to our own needs and scenarios. The above are just a few of the methods, and you can choose according to the actual situation. As UniApp continues to develop and improve, I believe there will be more and more convenient ways to set background images.
The above is the detailed content of How to put a background image on a page in uniapp. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools
