做用:選中指定的任意標籤設置屬性spa
1、同級別的第幾個,不區分類型ast
- first-child 選中同級別中的第一個標籤
- last-child 選中同級別中的最後一個標籤
- nth-child(n) 選中同級別中的第 n 個標籤
- nth-last-child(n) 選中同級別中的倒數第 n 個標籤
- only-child 選中父元素中惟一的標籤
例:p:first-child{color:red;}標籤
2、同級別 同類別的第幾個co
- first-of-type 選中同級別同類型中的第一個標籤
- last-of-type 選中同級別同類型中的最後一個標籤
- nth-of-type(n) 選中同級別同類型中的第 n 個標籤
- nth-last-of-type(n) 選中同級別同類型中的倒數第 n 個標籤
- only-of-type 選中父元素中惟一類型的某個標籤
3、其餘用法
- nth-child(odd) 選中同級別中的全部奇數
- nth-child(even) 選中同級別中的全部偶數
- nth-child(xn + y) x和y是用戶自定義的,而n是一個計數器,從0開始遞增
- nth-of-type(odd) 選中同級別同類型中的全部奇數
- nth-of-type(even) 選中同級別同類型中的全部偶數
- nth-of-type(xn + y) x和y是用戶自定義的,而n是一個計數器,從0開始遞增
注:摘自李南江老師筆記