為每個作為其父
元素的第 n 個
元素設定樣式
使用 CSS :nth-of-type(n) 選擇器為每個作為其父元素的第 n 個
元素設定樣式。你可以嘗試執行以下程式碼來實現 :nth-of-type(n) 選擇器
示例
<!DOCTYPE html> <html> <head> <style> p:nth-of-type(2) { background: yellow; } </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> </body> </html>
廣告