How can I change the background-color of the label from a checked radio button.
Django renders form radio inputs like this:
<label for="id_form-level_0">
<input type="radio" name="form-level" value="1" required="" id="id_form-level_0">
description
</label>
I dont have the intention to change this, so the most commun solution
input[type="radio"]:checked + label {
background-color: red;
}
does not work. In addition the :has() selector seems not to be supported in the browsers, meaning the following code neither works.
label:has(input[type="radio"]:checked) {
background-color: red;
}
What is the correct way to adress the right label in css?
2
Answers
if input checked, make inputs background red,
if inputs checked, make sibling labels background red. (label should come later than input )
Yes,
:has
pseudoclass dont work proper in FireFox (https://caniuse.com/css-has).This is impossible to select parent element in CSS.
It is unfortunate because you use
label
element as parent toinput
.