I have the following code:
<input id="checkboxWithGeneralSiblingSelector" type="checkbox"/>
<span id="span1">Text</span>
<br/><br/>
<input id="checkboxWithoutGeneralSiblingSelector" type="checkbox"/>
<span id="span2">Text2</span>
And CSS:
#checkboxWithGeneralSiblingSelector:checked ~ #span1 {
font-weight: bold;
}
#checkboxWithoutGeneralSiblingSelector:checked #span2 {
font-weight: bold;
}
The first one works fine, it looks at its general siblings and gets the element with ID span
, so I assumed the second one would look at the entire DOM and give me the element with id span2
. But then I realized that no operator is actually the "descendants" operator aka it looks for a span2
element inside the initially selected one.
This fiddle is oversimplified, in my case the span is in no relation with the checkbox, aka it cannot be selected with either +
, >
or ~
EDIT: Simplified example of my DOM:
<span id="toBeAffected">
...
<div>
<div>
<input id="trigger" type="checkbox"/>
</div>
</div>
How can I affect an item with no specific DOM relation to the current one, when the effect needs to be conditioned by a state of the initially selected item?