I am trying to change the default 'box image' of the checkbox with css, but it is not working. Is there any way arround this?
<input type="checkbox" class="class_checkbox">
And in the class file I do
.class_checkbox{
background: url("../images/button_bullet_normal.png") no-repeat scroll 0 0 transparent;
}
You can use pure css, just add a label to the checkbox like this:
I found another way, without using adjacent labels or surrounding divs.
My usecase was that I had a markdown parser that generates those nifty TODO lists and I wanted to style them. Changing the generated HTML wasn't a option, so I came up with this solution:
given a checkbox like this:
You can style it with
visibility: hidden
on checkbox andvisibility: visible
on ::after, like this:EDIT:
@connexo in a comment pointed out that input elements cannot have content. It could be easly done using label element, for example like so (please someone correct me if this is wrong, I don't have non-webkit browser handy to test it).
The checkbox works just like normal one and you can style it anyway you like.
Maybe it'll help someody (and I can bookmark it, because I haven't found anything like this on the web)
Here is a pure CSS way to change your checkbox style. I found it really useful, since I had already other functions related to the exact same checkboxes.
http://www.jotform.org/html-elements/css-checkbox-background-color/
BR's
Try:
jQuery
Fiddle: http://jsfiddle.net/cn6kn/
Maybe will be useful my sample with LESS.
I created a Fiddle using pure CSS. The most voted answer doesn't handle click events and won't work well, because the checkbox value won't change.
This is my example:
http://jsfiddle.net/kEHGN/1/
Basically, we need the following html:
And the following CSS:
Just check the routes of the images, and the widths and heights should be equal to the width and height of the images. On the fiddler I am using base64 encoded images.
I hope it can be useful.