I have successfully styled checkboxes with a background color, but now I want each checkbox to have a different color without having to rewrite a lot of code for each one.
.checkbox {
display: inline-block;
cursor: pointer;
font-size: 13px;
margin-right:10px;
line-height:18px;
}
input[type=checkbox] {
display:none;
}
.checkbox:before {
content:"";
display: inline-block;
width: 18px;
height: 18px;
vertical-align:middle;
background-color: red;
color: #f3f3f3;
text-align: center;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 3px;
}
.checkbox .pl {
background-color: blue;
}
input[type=checkbox]:checked + .checkbox:before {
content:"\2713";
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
font-size: 15px;
}
<input id="Option" type="checkbox">
<label class="checkbox pl" for="Option">Option 1</label>
<input id="option2" type="checkbox">
<label class="checkbox" for="option2">Option 2</label>
<input id="option3" type="checkbox">
<label class="checkbox" for="option3">Option 3</label>
<input id="option4" type="checkbox">
<label class="checkbox" for="option4">Option 4</label>
In my attempt to make the first checkbox blue, I encountered some issues. I am aware that I could achieve this by replicating the code for each checkbox, but I am searching for a more efficient solution.