This is a made-up example to represent a type of problem I have on a daily basis, when I'm using a content management system that sets up the HTML for tons of webpages and I need general ways of applying CSS according to mockups. I'm wondering if there is a non-Javascript way of solving it.
Suppose I have a div
of class some-div
, which will either have 1 or 2 child div
s. When it has 1 child div
, that child should have a red
background; when it has 2 child divs, they should have blue
backgrounds:
<div class="some-class">
<div>
<p>The background of this should be red.</p>
</div>
</div>
<div class="some-class">
<div>
<p>The background of this should be blue.</p>
</div>
<div>
<p>The background of this should be blue</p>
</div>
</div>
Is there a way of doing this in CSS? A hack, perhaps?