Home >Web Front-end >CSS Tutorial >How to set image background with css
How to set the image background in css: 1. Use the background-image attribute, the syntax "background-image:url('image address');"; 2. Use the background attribute, the syntax "background:url(' The map's address');".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
In css, you can use the background-image attribute or background attribute to set the image background.
css background-image property
The background-image property sets the background image of an element.
The background of an element is the total 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 vertically and horizontally.
Attribute value:
url('URL') Path pointing to the image.
none Default value. No background image is displayed.
inherit specifies that the setting of the background-image property should be inherited from the parent element.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css设置背景图片</title> <style> body { background-image: url('img/1.jpg'); } </style> </head> <body> </body> </html>
Rendering:
##css background attribute
The background attribute is a property specifically set for the background. It is a shorthand property that can set all background properties in one statement. (Learning video sharing:css video tutorial)
Background attributes that can be set:background-image:url(1.jpg);This is given in url() By specifying the path of the image, you can set a background image for the div box; it seems simple, but one thing to note is that the box for setting the background image must have substantial width and height, so that the background image can be displayed on the display.
background:url(bgimg.gif) no-repeat 5px 5px;Explanation as shown below: Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>背景图片设置</title> <style> .demo{ position:fixed; top: 0; left: 0; width:100%; height:100%; min-width: 1000px; z-index:-10; zoom: 1; background-color: #fff; background: url(img/1.jpg); background-repeat: no-repeat; background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-position: center 0; } </style> </head> <body> <div class="demo"></div> </body> </html>Rendering:
Introduction to Programming! !
The above is the detailed content of How to set image background with css. For more information, please follow other related articles on the PHP Chinese website!