This article uses HTML code and CSS style code to show you how to set the background color of HTML. There is also an introduction on how to set background image later. I hope it will be helpful to everyone, let’s take a look at this article now
First of all, let’s take a look at setting the background color in HTML:
us First, set a background color. Set the background color in the body tag and let's see the effect:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> </head> <body bgcolor="black"> 这是PHP中文网 </body> </html>
The background color is set to black. Can you think of the effect of displaying it in the browser?
Yes, this is the effect. Nothing can be seen. Let’s see if we can set the font to a color and see if it can be displayed:
<body bgcolor="black"> <p>这是<font color="#E41316">PHP中文网</font></p> </body>
Now let’s take a look at the effect:
Is it obvious that adding a color to the font can display the text, but there are still two words that have not been added color, so it still cannot be displayed.
Now let’s take a look at how to create a text background:
<body bgcolor="black"> <p style="background-color: #E12125">这是PHP中文网</p> </body>
The font tag no longer works at this time, so we decisively use css styles to change it. Background color, as you can see, this is a simple css style that only sets a background color.
Let’s take a look at the effect displayed in the browser:
Of course, you can also use pictures as background images. Let’s take a look at the effect examples:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> </head> <body style="background-image: url(https://img.php.cn/upload/article/000/000/003/5a9675a3b2106284.jpg)"> <p>这是PHP中文网</p> </body> </html>
HTML Learning Manual column. If you have any questions, you can leave a message below.
【Editor's Recommendation】How to set spaces in HTML paragraph elements? Summary of HTML space settings
#How to use the big tag in html? Usage examples of html big tag
The above is the detailed content of How to set background color in html? Detailed analysis of HTML background color code. For more information, please follow other related articles on the PHP Chinese website!