使用标准列表,我试图选择最后2个列表项。我一直的An+B
各种排列,但似乎没有选择最后2:是否可以选择最后n个项目与第n孩子?
li:nth-child(n+2) {} /* selects from the second onwards */
li:nth-child(n-2) {} /* selects everything */
li:nth-child(-n+2) {} /* selects first two only */
li:nth-child(-n-2) {} /* selects nothing */
我知道一个新的CSS3选择像:nth-last-child()
,但我喜欢的东西,在可能的话多了一些浏览器上运行(尤其不关心IE)。
IE尽管如此,对于`浏览器支持:第n-最后一子( )`与`:nth-child()`[根据quirksmode.org]大致相同(http://www.quirksmode.org/css/contents.html#t38)。另外,`:nth-child()`和`:nth-last-child()`都是在CSS3中引入的,在这个意义上,既不是老的也不是新的。 – BoltClock 2011-01-30 17:53:54