<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p:first-child {
color: red;
}
p:last-child {
color: aquamarine;
}
</style>
</head>
<body>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
<p>我是段落标签</p>
</body>
</html>
使用live server会使浏览器自动给我们所写的代码添加script标签,script标签会添加到body的最后,这就导致p标签不会成为body下的最后一个标签,就使css样式无法选中。而使用open in browser不会为我们的文件添加标签,就可以正常显示。
如果依然想要使用live server运行,可以在p标签外嵌套一个div,之后使用子代选择器选中p标签 ,即div>p:last-child{},来改变样式。