I have a list of checkboxes in a table. (one of the row CB in a row)
<tr><td><input type="checkbox" class="custom_image" value="1" id="CB1" /><label for='CB1'> </label></td></tr> <tr><td><input type="checkbox" class="custom_image" value="2" id="CB2" /><label for='CB2'> </label></td></tr> <tr><td><input type="checkbox" class="custom_image" value="3" id="CB3" /><label for='CB3'> </label></td></tr> <tr><td><input type="checkbox" class="custom_image" value="4" id="CB4" /><label for='CB4'> </label></td></tr>
I would like to replace the checkbox image with a pair of custom on / off images, and I was wondering if someone better understood how to do this using CSS?
I found this CSS Ninja tutorial, but I have to admit it's a little complicated for me. http://www.thecssninja.com/css/custom-inputs-using-css
As far as I can tell, you are allowed to use the pseudo-class
td:not(#foo) > input[type=checkbox] + label { background: url('/images/off.png') 0 0px no-repeat; height: 16px; padding: 0 0 0 0px; }
My guess was that by adding the above CSS, the checkbox would at least display the image in the OFF state by default, and then I would add the following to get ON
td:not(#foo) > input[type=checkbox]:checked + label { background: url('/images/on.png') 0 0px no-repeat; }
Unfortunately, it seems that I missed a critical step somewhere. I tried using my own CSS3 selector syntax to match my current setup, but should be missing something (16x16 images if that matters)
http://www.w3.org/TR/css3-selectors/#checked
EDIT: I missed something in the tutorial where it applies the image change to the label, not the input itself. I still don't get the expected replacement image for the checkbox result on the page, but I think I'm closer.
css checkbox css-selectors css3
Alex C Sep 22 '10 at 18:03 2010-09-22 18:03
source share