Home>Article>Web Front-end> How to set background image in css
How to set the background image in css: 1. Use the background-image attribute, the syntax "background-image:url(picture url);"; 2. Use the background attribute, the syntax "background:url(picture url) url);".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
In css, you can set the background image through the background-image attribute or background attribute.
The background-image attribute is used to set 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 both vertically and horizontally.
The background attribute is a shorthand attribute that can set all background attributes in one statement, including:
background -color specifies the background color to use
background-position specifies the position of the background image
background-size specifies the size of the background image
background-repeat Specifies how to repeat the background image
background-origin Specifies the positioning area of the background image
background-clip Specifies the drawing area of the background image
background-attachment Sets whether the background image is fixed or scrolls with the rest of the page
background-image specifies one or more background images to use
Example:
div { width: 450px; height: 360px; background: url(img/2.jpg); background-size: 450px;/*设置图片大小*/ }
(Learning video sharing:css video tutorial)
The above is the detailed content of How to set background image in css. For more information, please follow other related articles on the PHP Chinese website!