CSS选择下一个匹配 [英] CSS select next match
问题描述
有这样的布局:
<div class="a">
<div>
<div class="b">
<div class="b">...</div>
</div>
</div>
</div>
完全可以只对第一个div类b进行风格化而不必定义整个路径b ?
Is it at all possible to style only the first div class b without necessarily defining the entire path to b ?
.a .b {
border: 1px solid green;
} // Will style also the second b
.a > div > .b {
border: 1px solid red;
} // Path too strictly defined
当然我的结构简单,div类b中的内容可以是任何内容,因此我不想严格定义从下到b和所有其他元素的样式。
Off course my structure is not this simple, and the content inside the div class b can be anything, so I don't want to strictly define the styles from a down to b and all other elements.
应该有一个css选择器,表示第一个下一个匹配。
There should be a css selector which says "first next match".
推荐答案
应该有一个css选择器first next match strong>。
There should be a css selector which says "first next match".
好吧,没有。您将必须指定与您的元素匹配的确切结构,您已经使用 .a> div> .b
。如果有任何内部元素的样式需要重写,您需要为这些元素添加单独的规则。
Well, there isn't. You're going to have to specify the exact structure for which to match your element, which you already have done with .a > div > .b
. If there are any inner elements whose styles you need to override, you need to add separate rules for those elements.
这篇关于CSS选择下一个匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!