

代码:
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伪类
要配合锚点使用,表示被激活的状态
本文详细介绍了CSS中的各种选择器用法,包括基本的选择元素、奇数偶数元素、特定位置的元素等,并解释了如何使用伪类来进一步增强选择器的功能。
907

被折叠的 条评论
为什么被折叠?



