- span:nth-child(2):
选中是第二个孩子而且是span标签; - p:nth-of-type(2)
将所有孩子中的p标签拎出来,找到第2个。
<!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>
span:nth-child(2){
color: red;
}
p:nth-of-type(2){
color: orange;
}
</style>
</head>
<body>
<div>
<p>我是p标签,我是第一个孩子</p>
<span>我是span标签</span>
<p>我是p标签</p>
</div>
</body>
</html>