我们希望匹配父容器的最后12个元素。如何用CSS做到这一点?为了澄清,12是任意数字。我们想知道如何匹配父容器的最后N个元素。
答案 0 :(得分:5)
li:nth-last-child(-n+12) {
/*your css declarations*/
}
此示例选择器将匹配任何列表中的最后12个列表项,无论是有序还是无序:
答案 1 :(得分:2)
http://reference.sitepoint.com/css/pseudoclass-nthlastchild
li:nth-last-child(-n+12) {
⋮ declarations
}
答案 2 :(得分:1)
您需要:nth-last-child
pseudoclass(或:nth-last-of-type
进行类型检查)。之后,您可以使用~
选择所有后续兄弟姐妹:
.container > *:nth-last-child(13) ~ * { }