CSS:第一个孩子使用类 [英] CSS :first-child to work with classes
本文介绍了CSS:第一个孩子使用类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有这个标记:
<div class='current'>
</div>
<div class='current'>
</div>
<div class='current'>
</div>
<div class='current'>
</div>
<div class='current'>
</div>
现在这些div不一定在标记中彼此相邻,但可以遍布整个页面。
Now these divs are not necessarily next to each other in the markup, but could be spread throughout the page.
我只能使用CSS仅定位类current的第一次出现,我希望避免使用javascript(现在)?
Can i target only the first occurrence of class "current" using CSS only, i'd ideally like to avoid using javascript (for now)?
.current:first-child {
background: red;
}
推荐答案
这样的:
.current:nth-child(1){
background:red;
}
应该做的窍门!
这篇关于CSS:第一个孩子使用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文