Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the easiest way to put space between 2 side-by-side buttons in asp.net

I have 2 buttons side by side, and I would like to have some inbetween them.

Following code will have 2 buttons right next to each other. I have tried margin for the div, and just couldn't get some nice space between the two.

<div style="text-align: center">      <asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="89px" OnClick="btnSubmit_Click" />     <asp:Button ID="btnClear" runat="server" Text="Clear" Width="89px" OnClick="btnClear_Click" /> </div> 
like image 220
user570185 Avatar asked Feb 25 '11 16:02

user570185


People also ask

How do you add space between two buttons?

There are several methods that we can use to put spacing between two buttons. But the easiest way to achieve this is by using the margin property. You can either apply margin-right on the first button or margin-left on the second button. Both ways you can achieve the same task.


2 Answers

create a divider class as follows:

.divider{     width:5px;     height:auto;     display:inline-block; } 

Then attach this to a div between the two buttons

<div style="text-align: center">      <asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="89px" OnClick="btnSubmit_Click" />     <div class="divider"/>     <asp:Button ID="btnClear" runat="server" Text="Clear" Width="89px" OnClick="btnClear_Click" /> </div> 

This is the best way as it avoids the box model, which can be a pain on older browsers, and doesn't add any extra characters that would be picked up by a screen reader, so it is better for readability.

It's good to have a number of these types of divs for certain scenarios (my most used one is vert5spacer, similar to this but puts a block div with height 5 and width auto for spacing out items in a form etc.

like image 72
Michael Allen Avatar answered Sep 23 '22 02:09

Michael Allen


Add a space &nbsp; between them (or more depending on your preference)

    <div style="text-align: center">                  <asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="89px" OnClick="btnSubmit_Click" />         &nbsp;         <asp:Button ID="btnClear" runat="server" Text="Clear" Width="89px" OnClick="btnClear_Click" />     </div> 
like image 23
QuinnG Avatar answered Sep 22 '22 02:09

QuinnG