I am trying to style checkbox using the following:
<input type="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;" />
But, it is still displaying the default checkbox. How to do it?
|
UPDATE: The below answer references the state of things before widespread availability of CSS3. In modern browsers it is more possible to create checkbox replacements with your preferred styling. Here are some useful links:
It is worth noting that the fundamental issue has not changed. You still can't apply styles (borders, etc.) directly to the checkbox element and have those styles affect the display of the HTML checkbox. What has changed, however, is that it's now possible to hide the actual checkbox and replace it with a styled element of your own, using nothing but CSS. In particular, because CSS now has a OLDER ANSWER Here's a useful article about styling checkboxes. Basically what that writer found was that it varies tremendously from browser to browser, and that many browsers always display the default checkbox no matter how you style it. So there really isn't an easy way. It's not hard to imagine a workaround where you would use javascript to overlay an image on the checkbox and have clicks on that image cause the real checkbox to be checked. Users without javascript would see the default checkbox. Edited to add: here's a nice script that does this for you; it hides the real checkbox element, replaces it with a styled span, and redirects the click events. |
|||||||||
|
There is a way to do this using just css. We can (ab)use the label element and style that instead. The caveat is that this will not work for IE8 and lower versions. CSS:
HTML:
|
|||||||||||
|
Warning: the following was true at the time of writing, but in the meantime things have progressed. AFAIK modern browsers display checkboxes using the native OS control, so there's no way to style them. |
|||||
|
I think the easiest way to do it is by styling a label and making the check-box invisible. HTML
CSS
the |
|||||||
|
this the checkbox like with iPhone, it it used the pure css3 to create,pls view the tutorial:http://www.w3cplus.com/css3/css3-style-iphone-checkbox |
|||
|
You can achieve quite a cool custom checkbox effect by using the new abilities that come with the :after and :before psuedo classes. The advantage to this, is: You don't need to add anything more to the dom, just the standard checkbox. Note this will only work for compatible browsers, which unfortunately at the moment appears to be webkit only, but I am sure FF + IE, will work in the future (as no prefixes used) :) See example: http://jsfiddle.net/YMuPw/15/
|
||||
|