CSS setting div background image implementation code

CSS setting div background image implementation code

Adding background image control to a component requires only two steps:

<View
            className="gifts"
            style={{
              background: `url(${baseUrl}starMove/exclusiveEntrance/card.png) no-repeat`,
              backgroundSize: '100% 100%',
            }}
          >
          <View classname="gift-lists"></View>
</View>

Set background and backgroundSize.

style={

 width: 100%;
 height: 100%;
}

ps: Here is how to use CSS file to make the background image size adapt to the size of div

Setting the background image attribute: background-size: cover; can make the background image adapt to the size of the div.

background-size has 3 properties:

  • auto: When this property is used, the background image will remain displayed at 100% size without any scaling. Anything beyond the div will be hidden. When the image is too small, it will be automatically tiled. This property is often used to create a repeating background or a semi-transparent image background.
  • cover: When this attribute is used, the image will be scaled to just cover the div, and the hidden part of the image is minimal. This attribute is widely used in large image backgrounds. This is difficult to understand and requires practical application.
  • contain: When this attribute is used, the image is scaled to the maximum and can be fully displayed, but because the size ratio of the image is different from the size ratio of the div, when the image cannot cover the div, the image will be automatically tiled.

Summarize

This is the end of this article about the implementation code of setting div background image with CSS. For more relevant CSS div background image content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  A look into tool-based websites: the definition of tool-based websites and typical case analysis (pictures and text)

>>:  SQL implementation of LeetCode (182. Duplicate mailboxes)

Recommend

Example of disabling browser cache configuration in Vue project

When releasing a project, you will often encounte...

General Guide to Linux/CentOS Server Security Configuration

Linux is an open system. Many ready-made programs...

HTML drag and drop function implementation code

Based on Vue The core idea of ​​this function is ...

JavaScript event capture bubbling and capture details

Table of contents 1. Event Flow 1. Concept 2. DOM...

Summary of HTML Hack Tags in IE Browser

Copy code The code is as follows: <!--[if !IE]...

A brief discussion on how to learn JS step by step

Table of contents Overview 1. Clearly understand ...

Nginx content cache and common parameter configuration details

Use scenarios: The project's pages need to lo...

How to install and use Server-U 14 version

Introducing Server-U software Server-U is a very ...

Useful codes for web page creation

<br />How can I remove the scroll bar on the...

Detailed explanation of MySQL database paradigm

Preface: I have often heard about database paradi...

Vue implements custom "modal pop-up window" component example code

Table of contents Preface Rendering Example Code ...

Practice of realizing Echarts chart width and height adaptation in Vue

Table of contents 1. Install and import 2. Define...

vue-electron problem solution when using serialport

The error is as follows: Uncaught TypeError: Cann...

Specific method of viewing user authorization information in mysql

Specific method: 1. Open Command Prompt 2. Enter ...

How to generate Hive table creation statement comment script in MySQL metadata

Preface This article mainly introduces the releva...