Set the background color of different elements

This example demonstrates:

Set different background colors for h1, p, and div elements respectively.

Example analysis:

h1{background-color :#6495ed;}

p{background-color:#e0ffff; }

div{background-color:#b0c4de;}

Use the element selectors h1{}, p{}, and div{} to select the h1, p, and div elements in HTML respectively, and then use the background-color attribute in {} to set the background color


Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php(php.cn)</title>
<style>
h1
{
background-color:#6495ed;
}
p
{
background-color:#e0ffff;
}
div
{
background-color:#b0c4de;
}
</style>
</head>
<body>
<h1>CSS background-color !</h1>
<div>
div
<p></p>
div
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭