jQuery :nth-last-of-type() 选择器
定义和用法
:nth-last-of-type(n) 选择器用于选择其父元素的、特定类型的第 n 个子元素,从最后一个元素开始计数。
提示:使用 :nth-last-child() 选择器来选择其父元素的第 n 个子元素,无论类型如何,从最后一个元素开始计数。
语法
:nth-last-of-type(n|even|odd|公式)
参数 | 描述 |
---|---|
n | 要匹配的每个子元素的索引。 必须是一个数字。第一个元素的索引号为 1。 |
even | 选择每个偶数子元素 |
odd | 选择每个奇数子元素 |
formula | 使用公式(an + b)指定要选择的子元素。例如:p:nth-last-child(3n+2) 选择从最后一个第 2 个段落开始的每第 3 个段落。 |
自行尝试 - 示例
选择所有 <div> 元素的第一个 <p> 元素(从最后一个开始计数)
如何选择所有 <div> 元素的第一个 <p> 元素,从最后一个开始计数。
使用公式 (an + b)
如何使用公式(an + b)选择不同的 <p> 元素,从最后一个开始计数。
使用 "even" 和 "odd"
如何使用 even 和 odd 来选择不同的 <p> 元素,从最后一个开始计数。
p:nth-child(), p:nth-last-child(), p:nth-of-type() 和 p:nth-of-last-type() 之间的区别
p:nth-child(2), p:nth-last-child(2), p:nth-of-type(2) 和 p:nth-of-last-type(2) 之间的区别。