樣式化所有
其父元素的子元素,從最後一個子元素開始計數
使用 CSS :nth-last-child(n) 選擇器樣式化其父元素的每個 <p> 元素,從最後一個子元素開始計數。你可以嘗試執行以下程式碼來實施 :nth-last-child(n) 選擇器
範例
<!DOCTYPE html> <html> <head> <style> p:nth-last-child(4) { 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> <p>This is demo text 6.</p> </body> </html>
輸出
廣告