定义和用法

:nth-child( n ) 选择器选取属于其父元素的不限类型的第 n 个子元素的所有元素。

提示: 请使用 :nth-of-type() 选择器来选取属于其父元素的 特定类型 的第 n 个子元素的所有元素。

:nth-child( n |even|odd| formula ) 要匹配的每个子元素的索引。

必须是一个数字。第一个元素的索引号是 1。
选取每个偶数子元素。 选取每个奇数子元素。 formula 规定哪个子元素需通过公式 ( an + b ) 来选取。
实例:p:nth-child(3n+2) 选取每个第三段,从第二个子元素开始。 :nth-child()、:nth-last-child()、:nth-of-type() 和 :nth-of-last-type() 之间的不同
p:nth-child(2)、p:nth-last-child(2)、p:nth-of-type(2) 和 p:nth-last-of-type(2) 之间的不同。

jQuery 选择器 jQuery 选择器