标签:ref round type highlight css class 标签 script head
<!DOCTYPE html>
<html>
<head>
<style>
p:first-of-type
{
background:#ff0000;
}
/*body的第一个子元素是h1不是p,但body的第一个p子元素是存在的,所以first-of-type能选中,如果换成firs-child或者nth-child(1)就不行了*/
</style>
</head>
<body>
<h1>这是标题</h1>
<p>这是第一个段落。</p>
<p>这是第二个段落。</p>
<p>这是第三个段落。</p>
<p>这是第四个段落。</p>
</body>
</html>
http://www.w3school.com.cn/cssref/css_selectors.asp
伪类选择器:first-child和:nth-child()和:first-of-type
标签:ref round type highlight css class 标签 script head
原文地址:http://www.cnblogs.com/qdog/p/7081728.html