Reputation: 492
I have 2 divs on my site, they have the class X. Each of the divs is in another div, with a different class each, A and B for example.
<div class="A">
<div id="div1" class="X">something</div>
</div>
<div class="B">
<div id="div2" class="X">something else</div>
</div>
Now the content of those divs should be colored green. How can I say that both divs should be green using only one css class definition? Something like:
.A .B > .X {
color: green;
}
I hope you guys know what I mean?
Thanks!
Upvotes: 1
Views: 118
Reputation: 101604
You need to separate the rules (can't compound the parent like you are):
.A > .X,
.B > .X {
color: green;
}
The above stating "When an element has class A
or B
and the direct child has class X
, assign the text color to green
."
Upvotes: 6