我有类似如下结构:CSS - 隐藏标签第n + 2的div
<div class="group">
<div class="row1">
<label>Label 1A</label>
<input .../>
<label>Label 1B</label>
<input .../>
</div>
<div class="row2">
<label>Label 2A</label>
<input .../>
<label>Label 2B</label>
<input .../>
</div>
<div class="row3">
<label>Label 3A</label>
<input .../>
<label>Label 3B</label>
<input .../>
</div>
...
</div>
,但我想显示的标签仅在第一行。该结构是自动生成的,无法更改。 我尝试使用第n个孩子选择
.group:nth-child(n+2) div>label
,但不起作用。实际上,甚至.group:nth-child(n + 2)也无法选择n + 2个div。 我在做什么错?
编辑:请注意我不知道生成页面之前单行(row1,row2等)的类。
您是否尝试过隐藏所有的标签然后设置第一个显示? – Separatrix
你需要'.group'的'nnth-child(n + 2)'*,所以它应该是'.group:n-child(n + 2)label'(不是':'之前的空格)或'.group div:nth-child(n + 2)label'。或者,另一个替代方法是首先隐藏所有内容,然后将'.group div:first-child label'设置为可见。 – Harry
感谢您的出色答案。我会选择塞巴斯蒂安,因为他是第一个发布。 – algiogia