選擇每個
其父元素的倒數第二個
元素
使用 CSS :nth-last-of-type(n) 選擇器選擇其父元素的倒數第二個 <p> 元素。
示例
您可以嘗試執行以下程式碼來實現 :nth-last-of-type(n) 選擇器
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-last-of-type(2) {
background: blue;
color: white;
}
</style>
</head>
<body>
<p>This is demo text 1.</p>
<p>This is demo text 2.</p>
<p>This is demo text 3.</p>
<p>This is demo text 4.</p>
<p>This is demo text 5.</p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP