i want to put an image on the background of check box & radio box in my html code but it's not work but it's work on other form property.
This is what you need to do:Your checkboxes need to have distinct id attributes. This allows you to connect a <label> to it, using the label's for -attribute. Attaching the label to the checkbox will trigger a browser behaviour: Whenever someone clicks the label (or the image inside it), the checkbox will be toggled.
The <input type="image"> defines an image as a submit button. The path to the image is specified in the src attribute.
You can use a "label" tag that contains an "img" tag inside. Here's an example of using an image as a checkbox and radio. Show activity on this post.
I found the way how give image to checkbox & radio button with pure css.
HTML
<input type='checkbox' name='thing' value='valuable' id="thing"/><label for="thing"></label>
CSS
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked + label {
background: #0080FF;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
Check this for more http://css-tricks.com/the-checkbox-hack/ ,
https://gist.github.com/592332
I write my own code to fix this issue. This will work like this. I didn't have this code now but I write same way here on SO.
<div class="checkbox-wrapper">
<input type="checkbox" name="value"/>
<img src="img/blah.png"/>
</div>
In css we will hide this checkbox by make it's Z-index less then the image that I put inside this wrapper code. Eventwise when someone click on image it's look like checkbox and in real checkbox will be clicked. instead of display:none
using opacity:
0 will be better. This will break in IE6 but we didn't care about that because I am not supporting IE6 anymore.
In Javascript You can write event if you want a different (but similar to mine) implementation. You can replace native Html Checkbox,Radio and select (select2 is better if you stick with Twitter bootstrap) with your own themes based controls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With