Checkbox design
by Sparrow Squire
HTML
<input type="checkbox" name="foo" value="bar" id="foo" />
<label for="foo">This is a label</label>
CSS
input[type="checkbox"] {
margin: 0;
padding: 0;
width: 16px;
}
label {
position: relative;
}
label:before {
content: " ";
position: absolute;
left: -21px;
top: 0px;
display: inline-block;
width: 10px;
height: 10px;
padding: 2px;
background: #e5e5e5;
cursor: pointer;
border: 1px solid #999999;
text-align: center;
line-height: 10px;
vertical-align: top;
color: #555;
}
label.checked:before {
content: "\2713";
}
input:checked + label:before {
content: "\2713";
}
/* Fancy hover */
label:hover:before {
box-shadow: inset 0 0 2px 1px green;
}
JavaScript
$('input:checkbox').change(function() {
var label = $('label[for="'+$(this).attr('id')+'"]');
if ($(this).filter(":checked").length) {
label.addClass("checked");
} else {
label.removeClass("checked");
}
}).trigger("change");