<div class="one">
<div> </div>
<div class="three"> </div>
<div class="four"> </div>
</div>
<div class="one">
<div> </div>
<div class="three"> </div>
<div class="four"> </div>
</div>
<div class="one">
<div> </div>
<div> </div>
</div>
我想选择第四类的第一个 div,我不想选择第四类的任何其他 div,只选择第一个。
如何使用 CSS 实现这一点?
最佳答案
您可以简单地使用first-child
来做到这一点。你会调用你的类(class) + first-child
然后是 div。告诉它您只需要您调用的类的第一个实例。
one:first-child .four
表示您只想要第一个 one
类的 four
类。
这是一个例子:jsfiddle .
.one:first-child .four{
/* Your code here...*/
}
关于html - 如何使用 CSS 选择此 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31730256/