如果我们要获取到ul标签下面的第一个li标签来设置样式,有哪些css方法来实现呢?
一 获取第一个元素
1 使用 :first-child
ul li:first-child {
......
}
2 使用 :first-of-type
ul li:first-of-type {
......
}
3 使用 :nth-child
ul li:nth-child(1){
......
}
4 使用 :nth-of-type
ul li:nth-of-type(1){
......
}
二 获取非第一个元素
1 li:not(:first-child) //或者 :li:not(:first-of-type)
2 li+li //相邻选择器
3 li ~ li 兄弟选择器
4 li:nth-child(n+2) //由于n是从0开始的
网友评论