Home >Web Front-end >Front-end Q&A >How to set pictures in css

How to set pictures in css

藏色散人
藏色散人Original
2021-04-02 10:32:436302browse

How to set the image in css: first create an HTML sample file; then create a div in the body; finally set the image through "background-image: url("1.jpg");".

How to set pictures in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, DELL G3 computer

In CSS, you can use the background-image attribute to set the image . The background-image property sets the background image for the element. The background of an

element occupies the entire size of the element, including padding and borders, but not margins. By default, the background image is placed in the upper left corner of the element and repeats horizontally and vertically.

Depending on the value of the background-repeat property, the image can be tiled infinitely, tiled along an axis (x- or y-axis), or not tiled at all.

The initial background image (original image) is placed according to the value of the background-position attribute.

The value of the background-image attribute:

url('URL') points to the path to the image.

none Default value. No background image is displayed.

inherit specifies that the setting of the background-image attribute should be inherited from the parent element.

Tip: Please set an available background color so that the page can get good visual effects even if the background image is not available.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
div{
width:450px;
height: 300px;
background-image: url("1.jpg");
}
</style>
</head>
<body>
<div></div>
</body>
</html>

Rendering:

How to set pictures in css

Recommended study: "css video tutorial"

The above is the detailed content of How to set pictures in 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