Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set background color and image by CSS

Shulou Source: shulou.com Published: 2022-06-01 12:33:01 09月22日 Update

This article will explain in detail how to set background colors and images in CSS. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Let's first take a look at CSS setting the background color.

We need to use background-color to change the background color

Background-color:value (color coding or color name)

In the value section, you can enter a color code such as # 000000 or a color name such as white, and the set color is the background color.

The initial value of background-color is transparent, in which case the background color of the parent element is applied. If it is not set in the parent element, it turns white.

CSS sets the image background

By using the background-image property, we can pre-set the image uploaded to the server as the background.

Background-image:url ("path to Image")

In url, enter the path to the image file that you want to use as the background. If the css file and the image file are in the same directory, only the file name will be fine.

Both absolute and relative paths can be used as paths to image files.

To enter a relative path, enter the relative path of the external stylesheet, not the relative path of the html file.

Next, let's take a look at specific examples.

Use background-color to set the background color

The code is as follows

Body {

Background-color:skyblue

}

Background color settin

This is the end of the article on "how to set background colors and images in CSS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Color background image path file input article code element name more good practical content only attribute case file name article server Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn MySQL Redmi OPPO Reno