Hi there, I have a specific design requirement where I've created separate div sections for checkbox and label elements. I'm having trouble styling the checkbox when these elements are placed inside divs. Everything works fine when the checkbox and label are used without div sections, but once I add the divs, the styling doesn't work as expected. I've searched for solutions in various forums, but none of them seem to be solving my issue. Can anyone please take a look and assist me with this?
Useful links: How to Checkbox and label style only with CSS Forms, separate div for labels and inputs
.checkbox input[type=checkbox] + .checkmark label {
display: block;
margin: 0.2em;
cursor: pointer;
padding: 0.2em;
}
.checkbox input[type=checkbox] {
display: none;
}
.checkbox input[type=checkbox] + .checkmark label:before {
content: "\2714";
border: 0.1em solid #000;
border-radius: 0.2em;
display: inline-block;
width: 1em;
height: 1em;
padding-left: 0.2em;
padding-bottom: 0.3em;
margin-right: 0.2em;
vertical-align: bottom;
color: transparent;
transition: .2s;
}
.checkbox input[type=checkbox] + .checkmark label:active:before {
transform: scale(0);
}
.checkbox input[type=checkbox]:checked + .checkmark label:before {
background-color: MediumSeaGreen;
border-color: MediumSeaGreen;
color: #fff;
}
.checkbox input[type=checkbox]:disabled + .checkmark label:before {
transform: scale(1);
border-color: #aaa;
}
.checkbox input[type=checkbox]:checked:disabled + .checkmark label:before {
transform: scale(1);
background-color: #bfb;
border-color: #bfb;
}
<div class="checkbox">
<input type="checkbox" id="fruit1" name="fruit-1" value="Apple">
</div>
<div>
<label for="fruit1" class="checklabel">Apple</label>
</div>