代码:
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伪类
要配合锚点使用,表示被激活的状态