I'm styling labels to take place of the standard browser-defined radio button controls. I have a :hover
style and a :checked
style for the labels.
But it's not clear at a glance whether clicking a button will "uncheck" the currently-checked button. So I would like to change the style of the checked label when another label is hovered.
I have coded an example (JSFiddle).
Current Behavior:
(My screenshot tool removed it, but the cursor is over Radio Button Three. Radio Button One is checked.)
Desired Behavior:
HTML:
<form type="post">
<input type="radio" name="group" id="radio1" />
<label for="radio1">Radio Button One</label>
<input type="radio" name="group" id="radio2" />
<label for="radio2">Radio Button Two</label>
<input type="radio" name="group" id="radio3" />
<label for="radio3">Radio Button Three</label>
<input type="radio" name="group" id="radio4" />
<label for="radio4">Radio Button Four</label>
</form>
CSS:
input[type="radio"] {
display: none;
}
input[type="radio"] + label {
display: block;
width: 200px;
height: 30px;
text-align: center;
line-height: 30px;
background-color: white;
}
input[type="radio"] + label:hover {
background-color: blue;
color: white;
}
input[type="radio"]:checked + label {
background-color: red;
color: white;
}
If I have to use JS, I will, but pure CSS is preferable.