CSS Backgrounds
CSS backgrounds are used to add background images, colors, and gradients to HTML elements. CSS can be used to specify the background image, color, repeat, position, and other properties of backgrounds.
Background Image
The background-image property specifies the image that will be used as the background of an element. The background-image property can be set to the URL of an image file, or to a keyword that represents a built-in image.
For example, the following CSS rule will set the background image of all <h1> elements to the image file my-image.png:
h1 {
background-image: url(my-image.png);
}
Background Color
The background-color property specifies the color that will be used as the background of an element. The background-color property can be set to a hexadecimal color code, an RGB color value, or an HSL color value.
For example, the following CSS rule will set the background color of all <h1> elements to red:
h1 {
background-color: red;
}
Background Cover
CSS also includes a number of other background properties, such as background-size, background-attachment, and background-clip. These properties can be used to control the appearance of backgrounds in more detail.
For example, the following CSS rule will set the background size of all <h1> elements to cover the entire element:
h1 {
background-size: cover;
}
Task
Change the color and background-color of the header element to #fff and #333 respectively. Add background-image https://learnwith.tumkurlab.com/wp-content/uploads/2023/10/19449741-scaled.jpg to the body and make background-size cover. Add a form selector and change the background-color to #f2f2f2, light gray. Run the code to see the results and experiment with the code to get used to it.
Image by starline on Freepik