Okay, so I’ve seen lots of solutions for styling checkboxes via CSS on the web. However, I’m looking for something slightly more robust, and I’m wondering if someone can help. Basically, I want to have this solution, but with the ability to have a CSS-specified color overlaying a gray checkbox. I need this because I will have unpredictable numbers of different checkboxes, each needing a different color, and I don’t want to create vast amounts of different images to handle this. Anyone have any ideas on how to achieve this?
Share
I created a transparent png, where the outside is white, and the checkbox is partially transparent. I modified the code to put a backgroundColor on the element, and voila!, a colorized checkbox.
http://i48.tinypic.com/raz13m.jpg (It says jpg, but it’s a png).
I would post the example, but I don’t know of a good way to show it. Any good sandbox sites out there?
This, of course, depends on png support. You could poorly do this with gif, or put a semi-transparent css layer over the image, like you suggested, and then use a gif mask to mask out the bleed of the colored box. This method assumes transparency support.
My png method uses the css, js from the page you linked to, with these changes:
JS:
CSS:
HTML:
Hope that makes sense.
Edit:
Here is a jQuery example that illustrates the principle with checkboxes:
http://jsfiddle.net/jtbowden/xP2Ns/