How can I change checkbox (input) border's style? I've put border:1px solid #1e5180
upon it, but in FireFox 3.5, nothing happens!
views:
1762answers:
9Add a class in a style sheet:
.bordered { border: 1px solid #1e5180 }
Then add a div:
<div class="bordered">...</div>
That should work fine.
If something happens in any browser I'd be surprised. This is one of those outstanding form elements that browsers tend not to let you style that much, and that people usually try to replace with javascript so they can style/code something to look and act like a checkbox.
Here's an example: prettyCheckboxes.
Styling checkboxes (and many other input elements for that mater) is not really possible with pure css if you want to drastically change the visual appearance.
Your best bet is to implement something like jqTransform does which actually replaces you inputs with images and applies javascript behaviour to it to mimic a checkbox (or other element for that matter)
For Firefox, Chrome and Safari, nothing happens.
For IE the border is applied outside the checkbox (not as part of the checkbox), and the "fancy" shading effect in the checkbox is gone (displayed as an oldfashioned checkbox).
For Opera the border style is actually applying the border on the checkbox element.
Opera also handles other stylings on the checkbox better than other browsers: color is applied as the color of the tick, background-color is applied as background color inside the checkbox (IE applies the background as if the checkbox was inside a <div>
with background)).
Conclution
The easiest solution is to wrap the checkbox inside a <div>
like others have suggested.
If you want to completely control the appearance you will have to go with the advanced image/javascript approach, also meantiond by others.
<div style="border-style: solid;width:13px">
<input type="checkbox" name="mycheck" style="margin:0;padding:0;">
</input>
</div>
you should use
- -moz-appearance:none;
- -webkit-appearance:none; and
- -o-appearance:none;
then you get rid of the default checkbox image/style and can style it. Anyway a border will still there in Firefox