jQuery and ASP.NET

June 23, 2009

How to Reduce the Margin/Padding around a CheckBox




I was creating a HTML form recently which involved a lot of checkboxes. The client needed the space between the checkbox and the text to be reduced. An obvious choice was to reduce the Margin and Padding around the checkboxes, however this did not work around different browsers. I finally emulated the effect using the width of the checkbox. Here’s how:

<html xmlns="http://www.w3.org/1999/xhtml">

<
head>
<
meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<
title>Reduce Padding</title>
<
style type="text/css">
div
{
border:solid 1px;
}
input.chk {
width: 10px;
margin:0;
}
</style>
</
head>

<
body>
<
div>
<
input id="Checkbox1" type="checkbox"/> One <br />
<
input id="Checkbox2" type="checkbox"/> Two <br />
<
input id="Checkbox3" type="checkbox" class="chk"/> Three <br />
<
input id="Checkbox4" type="checkbox" class="chk"/> Four
</div>
</
body>

</
html>

Output

image

Check out the first two checkboxes which have the default width, margin and padding. Now check out the last two checkboxes which have a reduced width, margin and padding.

This tip should save time for those who have been trying to do the same using the margin and padding properties. The trick is to also set the width property.



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

2 Responses to "How to Reduce the Margin/Padding around a CheckBox"
  1. Anonymous said...
    October 15, 2009 2:58 PM

    I *adore* you. Fixed my little problem, thanks so much! Hugs, Bonney

  2. Anonymous said...
    March 7, 2011 1:57 AM

    Well, I was wondering where this mysterious margin came from and how to eliminate it - you've shown me the way! Thank you!
    Won't be the last time, this helped me - probably :)

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions