使用标准列表,我正在尝试选择最后2个列表项.我有各种各样的排列An+B
但似乎没有选择最后2:
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 */
Run Code Online (Sandbox Code Playgroud)
我知道有一个新的CSS3选择器,:nth-last-child()
但我更喜欢在可能的情况下在更多浏览器中工作的东西(尤其不关心IE).