是否可以选择最后n个项目与nth孩子? [英] Is it possible to select the last n items with nth-child?

查看:163
本文介绍了是否可以选择最后n个项目与nth孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用标准列表,我正在尝试选择最后2个列表项。我有 An + B 的各种排列,但似乎没有选择最后2个:

  li:nth-​​child(n + 2){} / *从第二个开始选择* / 
li:第n个孩子$ b li:nth-​​child(-n + 2){} / *只选择前两个* /
li:nth-​​child ::nth-​​last-child()



我知道一个新的CSS3选择器, / code>但是我更喜欢在可能的情况下在几个浏览器中工作的东西(不关心IE特别)。

解决方案

nth-last-child 听起来像是专门设计来解决这个问题,所以我怀疑是否有更兼容的替代品。但支持看起来体面的


Using a standard list, I'm trying to select the last 2 list items. I've various permutations of An+B but nothing seems to select the last 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 */

I'm aware of a new CSS3 selectors like :nth-last-child() but I'd prefer something that works in a few more browsers if possible (don't care about IE particularly).

解决方案

nth-last-child sounds like it was specifically designed to solve this problem, so I doubt whether there is a more compatible alternative. Support looks pretty decent, though.

这篇关于是否可以选择最后n个项目与nth孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆