最後一個型別選擇器

:last-of-type 選擇其父元素的特定型別的最後一個子元素。在下面的示例中,css 選擇最後一個段落和最後一個標題 h1

p:last-of-type { 
  background: #C5CAE9; 
}
h1:last-of-type { 
  background: #CDDC39; 
}
<div class="container">
    <p>First paragraph</p>
    <p>Second paragraph</p>
    <p>Last paragraph</p>
    <h1>Heading 1</h1>
    <h2>First heading 2</h2>
    <h2>Last heading 2</h2>
</div>

StackOverflow 文件

jsfiddle