Effect: <div class="imgs"> <!-- Background image --> <div class="background"> <img :src="item.voteTime ? imgSrc1:imgSrc2" width="100%" height="100%" alt="" /> </div> <!-- Text --> <div class="front"> <div v-if="item.voteTime"> <p>Thank you very much! </p> <p>You have voted: <span>{{item.voteTime}}</span></p> </div> <p v-else style="color:#999999">Sorry, you have not completed the voting~</p> </div> </div> data() { return { imgSrc1:require('@/common/imgs/yitoupiao.png'), imgSrc2:require('@/common/imgs/weiwancheng.png'), } }, The large div outside: set the width and height; .imgs { background: #fff; position: relative; width: 100%; height: 250px; color: #195541; .background{ // width:100%; // height:100%; /**The width and height are 100% so that the image fills the screen*/ // z-index:-1; z-index:1; position: absolute; width: 250px; height: 100%; right: 20px; bottom: 0px; } .front{ z-index:2; position: absolute; text-align: center; top: 39%; left: 25%; font-weight: normal; line-height: 40px; font-size: 28px; } } A bug was encountered during the development process: I initially set the z-index of the background image to -1, which resulted in the background image sometimes being displayed on the h5 and sometimes not. Later, I changed it to a positive number 1 to solve this problem. This is the end of this article about how to use CSS to put text on a background image. For more information about using CSS to put text on a background image, please search 123WORDPRESS.COM’s previous articles or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Use overflow: hidden to disable page scrollbars
>>: Docker container data volume named mount and anonymous mount issues
Table of contents Preface 1. Why do cross-domain ...
This article tests the environment: CentOS 7 64-b...
This article mainly introduces the principle and ...
◆Add to favorites illustrate Click to add your we...
Here's the thing: Everyone knows about "...
This article introduces the CSS scrollbar selecto...
1. Data backup 1. Use mysqldump command to back u...
The main contents of this article are as follows:...
Stored Functions What is a stored function: It en...
Modify the group to which a user belongs in Linux...
Preface We need to retrieve certain data that mee...
Table of contents Preface First look at React Con...
Why optimize: With the launch of the actual proje...
Understanding object.defineProperty to achieve re...
Method 1: Set the readonly attribute to true. INPU...