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

How to manage docker through UI

Docker is being used in more and more scenarios. ...

Implementation of multi-site configuration of Nginx on Mac M1

Note: nginx installed via brew Website root direc...

25 div+css programming tips and tricks

1. The ul tag has a padding value by default in M...

CSS controls the spacing between words through the letter-spacing property

letter-spacing property : Increase or decrease th...

How to create your own Docker image and upload it to Dockerhub

1. First register your own dockerhub account, reg...

js implements mouse switching pictures (without timer)

This article example shares the specific code of ...

Summary of events that browsers can register

Html event list General Events: onClick HTML: Mous...

Solve the problem of not finding NULL from set operation to mysql not like

An interesting discovery: There is a table with a...

Several ways to switch between Vue Tab and cache pages

Table of contents 1. How to switch 2. Dynamically...

How to set the default value of a MySQL field

Table of contents Preface: 1. Default value relat...

Summary of the benefits of deploying MySQL delayed slaves

Preface The master-slave replication relationship...

Several methods of implementing two fixed columns and one adaptive column in CSS

This article introduces several methods of implem...