The background property in CSS is used to set the background of web page elements, including colors, images, gradients and videos. Specific usage includes: setting background color: background-color: #f0f8ff; setting background image: background-image: url("background.jpg"); setting background position: background-position: center top; setting background repeat mode: background- repeat: repeat-x;Set background-attachment: fixed;In addition, bac
Usage of background in CSS
The background attribute in CSS is used to set the background of web page elements. It can specify a variety of background characteristics, including color, image, gradient and video.
Usage syntax:
background: ;
Parameter details:
Specific usage:
1. Set background color:
body { background-color: #f0f8ff; }
2. Set background Picture:
div { background-image: url("background.jpg"); }
3. Set background position:
header { background-position: center top; }
4. Set background repeat mode:
footer { background-repeat: repeat-x; }
5. Set background fixed:
#banner { background-attachment: fixed; }
Background gradient:
The background property also supports linear gradients and radial gradients. The syntax is as follows:
Linear gradient:
background: linear-gradient(to right, #000000, #ffffff);
Radial gradient:
background: radial-gradient(circle, #000000, #ffffff);
By flexibly using the background attribute, you can Web elements create rich visual effects.
The above is the detailed content of How to use background in css. For more information, please follow other related articles on the PHP Chinese website!