我有一个HTML列表,需要选择除第一个和最后一个元素以外的所有元素。
目前我的尝试是这样的:
.inputList li:not(:first-child):not(:last-child) {
// stuff
}
不太有效...有没有更好的方法,而且还能在IE上运行?
感谢提供意见!
我有一个HTML列表,需要选择除第一个和最后一个元素以外的所有元素。
目前我的尝试是这样的:
.inputList li:not(:first-child):not(:last-child) {
// stuff
}
不太有效...有没有更好的方法,而且还能在IE上运行?
感谢提供意见!
您可以为所有子元素指定一个声明,然后为第一个和最后一个子元素进行覆盖:
.example > LI {background: green; }
.example > LI:first-child,
.example > LI:last-child {background: none; }
写成这样:
.inputList li:first-child, .inputList li:last-child{
color:red;
}
注意::first-child
可在 IE7 及以上版本中使用。 :last-child
可在 IE9 及以上版本中使用。
第一个元素可以被忽略,因为
li + li{border-left: 1px solid #000;}
我刚刚发现了另一种方法来做这件事,所以只是为了文档而发布:
.inputList li + li:not(:last-child) {
background-color: green;
}
.education li:not(:last-child):after {
content: ",";
}