The way to change the background of an image in css is to add the background-image attribute and set the attribute value to the URL address of the image you want, for example [background-image:url('../images/ mix/paper.gif');].
The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.
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.
Common attribute values:
url('URL') URL of the image
none No image background will be displayed. This is the default
inherit Specifies that the background image should be inherited from the parent element
A simple code example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> body { background-image:url('../images/mix/paper.gif'); background-color:#cccccc; } </style> </head> <body> <h1>Hello World!</h1> </body> </html>
Related video sharing: css video tutorial
The above is the detailed content of How to change the background of an image with css. For more information, please follow other related articles on the PHP Chinese website!