<!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>Document</title>
<style>
.a-list:last-of-type {
color: red;
}
.b-list:first-of-type {
background: yellow;
}
</style>
</head>
<body>
<h1>我是标题</h1>
<span class="a-list">a0</span>
<p class="b-list">b0</p>
<p class="a-list">a1</p>
<p class="a-list">a2</p>
<p class="a-list">a3</p>
<span class="b-list">b1</span>
<span class="b-list">b2</span>
<span class="a-list">b3</span>
<p class="a-list">a4</p>
<p class="a-list">a5</p>
<p class="a-list">
a6
<span class="b-list">b4</span>
<span class="a-list">a7</span>
<span class="b-list">b5</span>
</p>
<h4 class="c-list">c1</h4>
<h4 class="a-list">c2</h4>
<h4 class="c-list">c3</h4>
</body>
</html>
nth-of-type(n)的作用模式是,先找到所有的对应的className,然后从当前className的标签找到所有当前标签元素的兄弟标签元素,然后按照位置先后顺序从1开始排序,看是否为第n个元素,是就加上样式,不是就不变。