7

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.

Can anyone provide C# code or css code that can do this?

1
  • Hi, this is totally possible in CSS. you can go see my answer and maybe accept it as the good answer if it works for you ? Commented Aug 4, 2017 at 14:19

8 Answers 8

29

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;}
Sign up to request clarification or add additional context in comments.

1 Comment

PLUS ONE for an awesome answer! Well done! Works like a charm for me!!!
3

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.

2 Comments

no. i donot want to use html control. i am talking about .net checkbox control.
@Sikender: The asp.net checkbox control renders similar to Jason's example.
3

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>

Comments

0

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>

Comments

0

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'>" />

Comments

0

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;
}

Comments

0

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;

Comments

-1

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:

5 Comments

It works in IE 6 and IE 7, but not 8, and not FF, and not chrome (and even in IE, its very pixelated).
@Sikender: Are you willing to use the AJAXControlToolkit (I recommend it)? If so, they have a toggle button control. You can simply specify the images, and it works: asp.net/ajax/ajaxcontroltoolkit/samples/ToggleButton/…
@Yannick Richard's solution works great as a css only solution.
You can do it. Minus 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.