In CSS, the background
property is used to set background styles for elements. You can apply backgrounds to elements using various methods, including color, images, gradients, and more.
The background-color
property sets the background color of an element. For example:
div {
background-color: #ff6347;
}
The background-image
property sets an image as the background of an element. For example:
div {
background-image: url('https://www.shariqsp.com/image1.jpg');
}
The background-image
property can also be used to create gradients. For example:
div {
background-image: linear-gradient(to right, #ff7e5f, #feb47b);
}
The background-position
property sets the position of a background image. For example:
div {
background-image: url('https://www.shariqsp.com/image1.jpg');
background-position: center;
}
The background-repeat
property sets how a background image repeats. For example:
div {
background-image: url('https://www.shariqsp.com/image1.jpg');
background-repeat: no-repeat;
}
The background-size
property sets the size of a background image. For example:
div {
background-image: url('https://www.shariqsp.com/image1.jpg');
background-size: contain;
}
The background-attachment
property sets whether a background image scrolls with the page or is fixed. For example:
div {
background-image: url('https://www.shariqsp.com/image1.jpg');
background-attachment: fixed;
}