我有两个 dhx_scroll_cont div类,当我编写css代码时,它正在为两个类工作。现在我想编写一个适用于第一个div调用的css代码
.dhx_scroll_cont:before{
//some code here
}
答案 0 :(得分:2)
只需使用:
.dhx_scroll_cont:first-of-type:before{
//some code here
}
:第一个类型的CSS伪类代表了第一个兄弟 它在父元素子元素列表中的类型。
<强>更新强>
根据the screenshot the OP posted,以下内容应该有效:
.dhx_view_day_events .dhx_scroll_cont:first-of-type:before{
//some code here
}
答案 1 :(得分:0)
根据HTML的结构,您需要的解决方案会发生变化。
您是否能够为我们提供HTML结构?
否则,您可以:
将另一个类添加到要更改的div
让<div class="dhx_scroll_cont">
只提供一个可定位的课程。解决这个问题的一种方法是使用空格分隔2个类,例如:
<div class="dhx_scroll_cont OTHER_CLASS">
这将允许您使用您想要影响第一个div的某些CSS值来定位类OTHER_CLASS
。
使用:first-child
或:first
:first-child
和:first
允许您定位作为其父级的第一个子元素的div。例如:
<div class="surround">
<div class="dhx_scroll_cont">
</div>
<div class="dhx_scroll_cont">
</div>
</div>
dhx_scroll_cont:first-child {
CSS HERE
}
这将影响第一个dhx_scroll_cont
div。
正如我之前所说,如果您可以提供有关HTMl结构的更多信息,这将有助于我们解决您的问题。
感谢您展示HTML结构。
使用我所显示的方法中的结构,在dhx_scroll_cont
的第一个中添加另一个类将允许您专门定位该div,而不是另一个。