Html 如何将第n个子对象仅与直接子对象一起使用?

Html 如何将第n个子对象仅与直接子对象一起使用?,html,css,Html,Css,我在下面的html中有这个,在我的CSS中我写了。CommentSection:nth child(5n) li.Hide不是每更改第五个评论框,而是更改其他元素。我如何使它只计算直接子项(总是div class=“comment”)并应用于其子项,而不计算其子项 <div class="CommentSection"> <div class="comment" id="c19"> <ul> <li class="userna

我在下面的html中有这个,在我的CSS中我写了
。CommentSection:nth child(5n)

li.Hide不是每更改第五个评论框,而是更改其他元素。我如何使它只计算直接子项(总是
div class=“comment”
)并应用于其子项,而不计算其子项

<div class="CommentSection">
  <div class="comment" id="c19">
    <ul>
        <li class="username">a</li>
        <li class="date">3/2/2010 6:14:51 AM</li>
        <li class="link"><a href="http://localhost:1223/u/a#c19">Permalink</a></li>
        <li class="flag">Flag</li>
        <li class="Hide"><a href="http://localhost:1223/u?hide=1&amp;t=8&amp;c=19&amp;ret=/u/a">Hide</a></li>
        <li class="delete">Delete</li>
        <li class="reply">Reply</li>
    </ul>

    <div class="text">
      <p>asd</p>
    </div>
  </div>
...
</div>

  • a
  • 2010年3月2日上午6:14:51
  • 删除
  • 回复
自闭症

...
.CommentSection>:第n个孩子(5n)
.CommentSection。注释:第n个孩子(5n)
尝试以下操作:

.CommentSection > div.comment:nth-child(5n)
这将选择每5个
DIV
,其中类注释是CommentSection的直接子级。

试试这个

.CommentSection .comment:nth-child(5n){
  […]
}
或者更具体地说:

.CommentSection > .comment:nth-child(5n) {
  […]
}
这也应该很好:

.CommentSection > :nth-child(5n) {
  […]
}

真的是Alex Gyoshev?你能举出一个消息来源吗?