I really tried a lot to increase a size of checkbox in asp.net. using css style sheet but it doesn't work.
Might be I have done something wrong. I am try to increase the width, size and height of checkbox, but it doesnt happen yet.
开发者_JS百科Can anyone provide C# code or css code that can do this?
In asp.net a checkbox will become a span with an input of type "checkbox"
In order to resize it, just apply a css class to the asp.net checkbox and add this to your style sheet. the style must be applied to the the embeded input of the checkbox like this :
<asp:CheckBox ID="chkBoxName" runat="server" CssClass="ChkBoxClass"/>
.ChkBoxClass input {width:25px; height:25px;}
Having a html checkbox.
<input type="checkbox" id="fatty">
<label for="checkbox-1">Checkbox 1</label>
fatty { /* Change width and height */
width:4em;
height:4em;
}
I got this from here.
A little late to the party but I'll leave this here for anyone else that needs help making check boxes bigger.
input[type=checkbox] {
-ms-transform: scale(3); /* IE */
-moz-transform: scale(3); /* FF */
-webkit-transform: scale(3); /* Safari and Chrome */
-o-transform: scale(3); /* Opera */
}
Example provided in the code snippet.
.scale1 {
margin: 15px;
-ms-transform: scale(1); /* IE */
-moz-transform: scale(1); /* FF */
-webkit-transform: scale(1); /* Safari and Chrome */
-o-transform: scale(1); /* Opera */
}
.scale2 {
margin: 15px;
-ms-transform: scale(2); /* IE */
-moz-transform: scale(2); /* FF */
-webkit-transform: scale(2); /* Safari and Chrome */
-o-transform: scale(2); /* Opera */
}
.scale3 {
margin: 15px;
-ms-transform: scale(3); /* IE */
-moz-transform: scale(3); /* FF */
-webkit-transform: scale(3); /* Safari and Chrome */
-o-transform: scale(3); /* Opera */
}
<input id="cb1" type="checkbox" class="scale1">
<label for="cb1">scale1 </label>
<input id="cb2" type="checkbox" class="scale2">
<label for="cb2">scale2 </label>
<input id="cb3" type="checkbox" class="scale3">
<label for="cb3">scale3 </label>
for some reason, this doesn't worked for me:
<asp:CheckBox id="requestAccountCB" style="width: 20px; height: 20px;" runat="server"/>
but this worked:
<style>
#requestAccountCB { width: 20px; height: 20px }
</style>
...
<body>
<form runat="server">
<asp:CheckBox id="requestAccountCB" runat="server"/>
</form>
</body>
As mentioned above, this can't be done.
What you can do is add a tag inside the checkbox and set a background image to that tag. It's all done with css and it works perfectly.
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
background-image: url('images/off.gif');
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked + label
{
background-image: url('images/on.gif');
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
And HTML code:
<input type='checkbox' name='thing' value='valuable' id="thing"/><label for="thing"></label>
The code can be found in this fiddle.
I found this solution here.
BTW: if you're using ASP.NET like me, you can add the label tag as so:
<asp:CheckBox runat="server" ID="chkEmailForUnpluggedService" Text="<label for='thing'>" />
This solution works perfect for me:
Html Rendered looks like this:
<span class="15465503">
<input id="ctl00_ctl00_ctl00_BB_SB_ScB_ucSR_rptR_ctl01_chkShortlist"
type="checkbox" name="ctl00$ctl00$ctl00$BB$SB$ScB$ucSR$rptR$ctl01$chkShortlist");">
</span>
CSS to change the check box size is:
input[id$="chkShortlist"] {
width: 18px;
height: 18px;
}
In 2021, if anybody still needs help with this - the multitude of answers above did not help me resize an ASP checkbox in an old WebForms application. Instead, adding the checkbox as a standard HTML Input element (as type="checkbox"), as opposed to an ASP:CheckBox, and then setting runat="server", helped me to be able to control this with inline styles, whilst still being able to control this in the code behind. E.g.
<input type="checkbox" id="cbInputDamagedStatus" style="width:1.5em; height:1.5em; display: inline-block;" runat="server" />
and
cbInputDamagedStatus.Checked = true;
You can't do it. A Checkbox is a windowed browser component. The best you can do is to make your own control that LOOKS like a checkbox, but is actually made up of an image for each state.
Here are some examples of controls that use images instead of checkboxes:
- ASP.Net AJAX AJAXControlToolkit
- CodeProject example
- Checkboxes and radiobuttons
- ImageCheckbox
精彩评论