Home  >  Article  >  Web Front-end  >  How to modify the background image width and height with css

How to modify the background image width and height with css

藏色散人
藏色散人Original
2020-12-18 10:21:5414247browse

How to modify the width and height of the background image in css: first create an HTML sample file; then use the "background-image" attribute to set the background image of the div to "a.jpg" under the images folder; finally use " background-size" to adjust the size of the background image.

How to modify the background image width and height with css

The operating environment of this tutorial: Windows7 system, HTML5&&CSS3 version. This method is suitable for all brands of computers.

Recommended: "css video tutorial"

CSS method to modify the width and height (size) of the background image

In CSS , you can use the background-siz attribute to modify the width and height (size) of the background image.

The background-size attribute can set the width and height of the background image, which can be a percentage value or pixel (px) unit.

Example:

Use the background-image attribute to set the background image of the div to a.jpg under the images folder, and use background-repeat to set the background image so that it does not display repeatedly.

How to modify the background image width and height with css

Rendering: Unmodified width and height of the background image

How to modify the background image width and height with css

Use background-size to adjust the size of the background image. The first parameter value is the width, and the second parameter value is the height. For example, set the height and width of the background image to half of the original value, that is, 50%.

How to modify the background image width and height with css

Open the test.html file in the browser to check the effect.

How to modify the background image width and height with css

The above is the detailed content of How to modify the background image width and height with css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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