I'm using checkboxes based on Brad Bodine's examples here. I'm thrilled with the abilities his examples gave me, but I do have one question.
I'm using slideThree (see the CSS below). It works like a charm, but I would like to change the background color of the parent DIV based on the position of the slider. I thought that maybe one of the two examples below would do it:
.slideThree input[type=checkbox]:checked { background: green; }
.slideThree input[type=checkbox]:checked + div { background: green; }
But neither one worked. Is it possible to change the background based on the selected state of the INPUT?
HTML
<div class="slideThree">
<input type="checkbox" value="None" id="test" name="check" checked />
<label for="test"></label>
</div>
CSS
/* .slideThree */
.slideThree {
width: 80px;
height: 26px;
background: #333;
margin: 20px auto;
position: relative;
border-radius: 50px;
box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.2);
}
.slideThree:after {
content: 'OFF';
color: #000;
position: absolute;
right: 10px;
z-index: 0;
font: 12px/26px Arial, sans-serif;
font-weight: bold;
text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.15);
}
.slideThree:before {
content: 'ON';
color: #27ae60;
position: absolute;
left: 10px;
z-index: 0;
font: 12px/26px Arial, sans-serif;
font-weight: bold;
}
.slideThree label {
display: block;
width: 34px;
height: 20px;
cursor: pointer;
position: absolute;
top: 3px;
left: 3px;
z-index: 1;
background: #fcfff4;
background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
border-radius: 50px;
-webkit-transition: all 0.4s ease;
transition: all 0.4s ease;
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.3);
}
.slideThree input[type=checkbox] {
visibility: hidden;
}
.slideThree input[type=checkbox]:checked + label {
left: 43px;
}
/* end .slideThree */