CSS3新增nth-of-type选择器及与nth-child区别
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS3新增nth-of-type选择器</title>
<style>
ul li:first-of-type {
background-color: tomato;
}
ul li:nth-of-type(even) {
background-color: skyblue;
}
section div:nth-child(1) {
background-color: red;
}
section div:nth-of-type(1) {
background-color: blue;
}
</style>
</head>
<ul>
<li>我是第1个孩子</li>
<li>我是第2个孩子</li>
<li>我是第3个孩子</li>
<li>我是第4个孩子</li>
<li>我是第5个孩子</li>
<li>我是第6个孩子</li>
<li>我是第7个孩子</li>
<li>我是第8个孩子</li>
</ul>
<section>
<p>光头强</p>
<div>熊大</div>
<div>熊二</div>
</section>
<body>
</body>
</html>
效果展示
