Home > Article > Web Front-end > How to set background image in css
The way to set the background image in css is to use the background-image attribute, such as [background-image:url();]. An element's background takes up the full size of the element, including padding and borders, but not margins.
The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.
In CSS we can use the background-image attribute to set a background image for an element. An element's background 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.
For example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> <style> body { background-image:url('https://xxx.com/images/mix/paper.gif'); background-color:#cccccc; } </style> </head> <body> <h1>Hello World!</h1> </body> </html>
Related 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!