使用CSS为其父元素的最后一个
元素设置每个
元素的样式
使用CSS:last-child选择器为每个<p>元素(其父元素的最后一个子元素)设置样式。您可以尝试运行以下代码来实现:last-child选择器
<!DOCTYPE html>
<html>
<head>
<style>
p:last-of-type {
background: orange;
}
</style>
</head>
<body>
<h2>Heading</h2>
<p>This is demo text1.</p>
<p>This is demo text2.</p>
<p>This is demo text3.</p>
</body>
</html>