How to set background color in html? Detailed analysis of HTML background color code

寻∝梦
Release: 2018-09-11 13:38:33
Original
115031 people have browsed it

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>
Copy after login

The background color is set to black. Can you think of the effect of displaying it in the browser?

How to set background color in html? Detailed analysis of HTML background color code

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>
Copy after login

Now let’s take a look at the effect:

How to set background color in html? Detailed analysis of HTML background color code

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>
Copy after login

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:

How to set background color in html? Detailed analysis of HTML background color code

##Because of the p tag, the background It occupies the entire row. This way the effect looks more obvious, so I won’t frame it. I’ll just teach you the method. When we can’t use so much background, we can add a div tag around the p tag and set the width. is the width of the text, so that the text background will not be displayed in one line. This is also one of the commonly used methods.

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>
Copy after login
This is a picture copied from the Internet, and the effect is still very good Obviously, let’s look at the example now:


How to set background color in html? Detailed analysis of HTML background color code

This is used as the background of the entire web page. We can find good-looking pictures from other places that are suitable for use as background images. We can right-click on that picture, select copy image address, and add it to this URL. This is also very simple. You can practice more below to see if the effect is the same as mine.

This article about setting the background color in HTML ends here. If you want to learn more, go to the PHP Chinese website and learn in the

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template