Reputation: 1288
Is there a way to style a checkbox and a label with border, so the user can see only the label (the checkbox is hidden), and when the user clicks on the label, the label will change the color of the background and the text? This click should also work as clicking on the checkbox. If there is a way, how should I do this?
or
How to hide the checkbox and leave only the label do the work with changing colors?
Upvotes: 2
Views: 2468
Reputation: 196236
Put them side to side (in html structure) and use the adjacent sibling selector +
Something like this
html
<input type="checkbox" id="box1" />
<label for="box1">checkbox #1</label>
css
input[type="checkbox"]{
position:absolute;
visibility:hidden;
z-index:-1;
}
input[type="checkbox"]:checked + label{
color:red;
}
you could style the label (2nd rule) as you want of course..
demo at http://jsfiddle.net/kb67J/1/
Upvotes: 5