Imagine this interesting situation in HTML:
<div class="red">
<div class="blue">
... <-- maybe more nested parents
<div class="x">Test</div>
</div>
</div>
If we consider the following CSS:
.blue.x, .blue .x {
background: blue;
}
.red.x, .red .x {
background: red;
}
In this instance, the background of the x element will unquestionably be red. This is because both rules apply, and the red background was defined last.
But how can we create a rule to ensure that the inner "blue" class (the closer parent to x) takes precedence? The goal is to alter the color based on the class structure, rather than the order in which the rules appear in the CSS file.