我有一个div标签包含几个ul标签。
我只能为第一个ul标签设置CSS属性:
div ul:first-child {
background-color: #900;
}
然而,我下面的尝试为其他ul标签设置CSS属性除了第一个不工作:
div ul:not:first-child {
background-color: #900;
}
div ul:not(:first-child) {
background-color: #900;
}
div ul:first-child:after {
background-color: #900;
}
我怎么能写在CSS:“每个元素,除了第一个”?
你可以像下面这样使用:not你可以使用:not()里面的任何选择器
any_CSS_selector:not(any_other_CSS_selector){
/*YOUR STYLE*/
}
你也可以使用:not without parent selector。
:not(:nth-child(2)){
/*YOUR STYLE*/
}
更多的例子
any_CSS_selector:not(:first-child){
/*YOUR STYLE*/
}
any_CSS_selector:not(:first-of-type){
/*YOUR STYLE*/
}
any_CSS_selector:not(:checked){
/*YOUR STYLE*/
}
any_CSS_selector:not(:last-child){
/*YOUR STYLE*/
}
any_CSS_selector:not(:last-of-type){
/*YOUR STYLE*/
}
any_CSS_selector:not(:first-of-type){
/*YOUR STYLE*/
}
any_CSS_selector:not(:nth-last-of-type(2)){
/*YOUR STYLE*/
}
any_CSS_selector:not(:nth-last-child(2)){
/*YOUR STYLE*/
}
any_CSS_selector:not(:nth-child(2)){
/*YOUR STYLE*/
}