代碼:
li:first-child{
background-color: pink;
}
li:nth-child(10){
background-color: pink;
}
li:last-child{
background-color: pink;
}
li:nth-child(odd+1){
background-color: black;
}
/*n表示0,1,2,3....*/
li:nth-child(n){
background-color: aquamarine;
}
/*偶數*/
li:nth-child(2n){
background-color: blueviolet;
}
/*選中前5個*/
li:nth-child(-n+5){
background-color: orangered;
}
/*選中後5個*/
li:nth-last-child(-n+5){
background-color: orangered;
}
/*選中7的倍數*/
li:nth-child(7n){
background-color: orange;
}
/*選中第六排*/
li:nth-child(7n-1){
background-color: aliceblue;
}
2.. Empty僞類
/*如果div為空,保證被選中*/
div:empty{
background-color: red;
}
3. Target僞類
要配合錨點使用,表示被激活的狀态