【问题标题】:How to select last three child elements with help of :nth-child [duplicate]如何在:nth-​​child 的帮助下选择最后三个子元素 [重复]
【发布时间】:2015-08-02 21:07:33
【问题描述】:

使用此代码,我可以选择前三个子元素:

span:nth-child(-n+3)

是否可以以相同的方式选择最后三个子元素?

这是 jsfiddle 中的一个示例:http://jsfiddle.net/nqhtzkaw/

更新:

这是答案:(感谢 Manoj Kumar)

/* First three items. */
span:nth-child(-n+3) {
}

/* Last three items. */
span:nth-last-child(-n+3) {
}

http://jsfiddle.net/infous/q61x0t3v/

支持它的浏览器:http://caniuse.com/#search=nth-last-child

【问题讨论】:

    标签: css


    【解决方案1】:
    span:nth-last-child(-n+3)
    

    它选择最后 3 个元素

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 2020-02-20
    • 2013-04-04
    • 1970-01-01
    相关资源
    最近更新 更多