In a div wrapper, I have some radio buttons. When one is selected, I wish to make the label for it have a certain background color. How specific can I be in the CSS rule for this?
HTML:
<div class="switch-wrapper">
<form>
<input id="id-1" class="my-switch-on" type="radio" />
<label for="id-1">Yes</label>
<input id="id-2" class="my-switch-off" type="radio" />
<label for="id-2">No</label>
</form>
</div>
My closest guess:
div.switch-wrapper input[type="radio"].my-switch-on+label {
background-color: #000;
}
But I can't get it to work. What I did instead was this:
input[type="radio"]:checked + label {
background: #000;
}
Which certainly work, but I'd like to know how to combine the plus selector with other types of selectors and classes. Is it possible? Can you group selectors with parenthesis? E.g.:
div.foo form.bar + div > span {
background-color: #000;
}
Which selector has precedence? Can't do more than one?
I mostly do backend engineering so front-end isn't my strong suit. Grateful for any tips or guidelines, links to specs I didn't find an/or short answers. :)