Skip to main content

结构伪类 nth-last-child

  • :nth-last-child() 的语法跟 :nth-child() 类似,不同点是 :nth-last-child() 从最后一个子元素开始往前计数
    • :nth-last-child(1),代表倒数第一个子元素
    • :nth-last-child(-n + 2),代表最后 2 个子元素

:nth-last-child() 这个 CSS 伪类从兄弟节点中从后往前匹配处于某些位置的元素。

/* 在所有兄弟节点中,从后往前
选择所有 4 的倍数的节点 */
:nth-last-child(4n) {
color: lime;
}
备注

这个伪类和 :nth-child 基本一致,但它是从 结尾 计数,而不是从开始计数。


Loading Github Gist ...
Details