【发布时间】:2014-01-13 14:36:38
【问题描述】:
第n个类型
我希望能够通过 nth-of-type 调用它们“第一、第二、第三”来获取 div 现在的问题是这行得通:
.box:nth-of-type(1)
.box:nth-of-type(3)
.box:nth-of-type(5)
但我不明白为什么我不能这样称呼他们:
.box:nth-of-type(1)
.box:nth-of-type(2)
.box:nth-of-type(3)
事情是这样的:
<div class="box"></div>
<div class="divider"></div>
<div class="box"></div>
<div class="divider"></div>
<div class="box"></div>
当我删除它们之间的两个分隔符时问题得到解决(有 2 个称为“分隔符”的 div),所以我可以将它们称为 1、2、3,但为什么我需要称它们为 1、3 , 5 用分频器?此外,当我将 div 更改为 p 或 h1 等其他任何内容时...没关系,我可以称它们为 1、2、3
感谢您的帮助!
【问题讨论】:
-
你会想要
:nth-match()(当它被实现时),而不是:nth-of-type()。
标签: javascript jquery css html