案例:CSS3 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<style>
5
p:first-child
6
{
7
background-color:yellow;
8
}
9
</style>
10
</head>
11
<body>
12
13
<p>这个段落是其父元素(body)的首个子元素。</p>
14
15
<h1>欢迎访问我的主页</h1>
16
<p>这个段落不是其父元素的首个子元素。</p>
17
18
<div>
19
<p>这个段落是其父元素(div)的首个子元素。</p>
20
<p>这个段落不是其父元素的首个子元素。</p>
21
</div>
22
23
<p><b>注释:</b>对于 IE8 及更早版本的浏览器中的 :first-child,必须声明 &lt;!DOCTYPE&gt;
24
25
</body>
26
</html>