我们想匹配父容器的最后 12 个元素。如何用 CSS 做到这一点?澄清一下,12 是一个任意数字。我们想知道如何匹配父容器的最后 N 个元素。
问问题
101 次
3 回答
5
明确地: nth- last-child(N)
li:nth-last-child(-n+12) {
/*your css declarations*/
}
此示例选择器将匹配任何列表中的最后 12 个列表项,无论是有序的还是无序的:
于 2012-09-14T18:45:45.927 回答
2
http://reference.sitepoint.com/css/pseudoclass-nthlastchild
li:nth-last-child(-n+12) {
⋮ declarations
}
于 2012-09-14T18:44:57.610 回答
1
您想要:nth-last-child
伪类(或:nth-last-of-type
用于类型检查)。之后,您可以使用~
选择所有后续兄弟姐妹:
.container > *:nth-last-child(13) ~ * { }
于 2012-09-14T18:44:19.023 回答