2012-03-21 131 views

回答

7

您可以所有子元素指定一个声明,然后覆盖它第一个和最后的孩子。例如:

.example > LI {background: green; } 

.example > LI:first-child, 
.example > LI:last-child {background: none; } 
+0

我会这样做。 – deed02392 2012-03-21 11:04:09

+0

是。我想这是要走的路。谢谢! – frequent 2012-03-21 11:07:03

5

这样写:

.inputList li:first-child, .inputList li:last-child{ 
    color:red; 
} 

:first-child工作,直到上述IE7 &。 :last-child工作到IE9 &以上。

+0

我需要所有的但是第一个和最后一个元素。 – frequent 2012-03-21 11:01:03

+1

还要感谢IE中的信息。 – frequent 2012-03-21 11:14:08

2

第一个元素可以被忽略,因为

li + li{border-left: 1px solid #000;} 
相关问题