Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make space between two buttons in same div?

What is the best way to horizontally space Bootstrap buttons?

At the moment the buttons are touching:

<div class="btn-group">
    <button class="btn btn-inverse dropdown-toggle" data-toggle="dropdown">
        <i class="icon-in-button"></i>  
        Add to list
        <span class="caret"/>
    </button>
    <ul class="dropdown-menu">
        <li>
            <a href="#">here</a>
        </li>
        <li>
            <a href="#">new</a>
        </li>
    </ul>
    <button class="btn btn-info">
        <i class="icon-in-button"></i>  
        more
    </button>
</div>

Two Bootstrap buttons

jsfiddle showing the problem: http://jsfiddle.net/hhimanshu/sYLRq/4/

like image 209
daydreamer Avatar asked Jun 26 '12 22:06

daydreamer


People also ask

How do you put a space between two icons in HTML?

Just apply a padding (or a margin, depending on the style you've used) between elements, e.g. Show activity on this post. you have to use padding attribute in style tag.

How do you put a space between buttons in Javascript?

You can use &nbsp; or margin property to add spacing between buttons on a webpage.

How can I add the space between two buttons in HTML?

Give your buttons id attributes, then you can use CSS to target the buttons and give them margins. Originally Answered: How can I add the space between two buttons on a basic HTML program? well, in html for space we use &nbsp, but if you use css then you can do this with the help of padding, margin, etc.

How to add permanent spacing between two buttons?

Add class="btn-block" to your buttons. This will provide permanent spacing. Show activity on this post. If you want use margin, remove the class on every button and use :last-child CSS selector.

How to add multiple buttons in one column?

Find the row and column where you want to place the buttons. In the column settings, go to the Advanced tab to the CSS Class. Add the class “pa-inline-buttons” and save. Next, add the following snippet your Divi>Theme Options>Custom CSS box. Now you can go ahead and add two or more Button Modules there in that column.

Can I place two Divi buttons next to each other?

This quick Divi Pro Tip will show you how to place two button modules side by side in the same column with a simple and easy solution. There are many times you want to place two Divi buttons next to each other, but you just can’t. Sure, you could try adding button modules to different columns, but sometimes that’s not practical.


10 Answers

Put them inside btn-toolbar or some other container, not btn-group. btn-group joins them together. More info on Bootstrap documentation.

Edit: The original question was for Bootstrap 2.x, but the same is still valid for Bootstrap 3 and Bootstrap 4.

In Bootstrap 4 you will need to add appropriate margin to your groups using utility classes, such as mx-2.

like image 94
Miroslav Popovic Avatar answered Sep 28 '22 07:09

Miroslav Popovic


Just put the buttons in a class ( class="btn-toolbar" ) as told by bro Miroslav Popovic.It works awesome.

<div class="btn-toolbar">
  <button type="button" id="btnSubmit" class="btn btn-primary btn-sm">Submit</button>
  <button type="button" id="btnCancel" class="btn btn-primary btn-sm">Cancel</button>
</div>
like image 36
Manmohan Avatar answered Sep 28 '22 07:09

Manmohan


You can use spacing for Bootstrap and no need for any additional CSS. Just add the classes to your buttons. This is for version 4.

like image 42
Dragan B. Avatar answered Sep 28 '22 07:09

Dragan B.


What Dragan B suggested is right way to go for Bootstrap 4. I have put one example below. e.g. mr-3 is margin-right:1rem!important

<div class="btn-toolbar pull-right">
   <button type="button" class="btn mr-3">btn1</button>
   <button type="button" class="btn mr-3">btn2</button>
   <button type="button" class="btn">btn3</button>
</div>

p.s: in my case I wanted my buttons to be displayed to the right of the screen and hence pull-right.

like image 20
mrana Avatar answered Sep 28 '22 07:09

mrana


you should use bootstrap v.4

<div class="form-group row">
    <div class="col-md-6">
        <input type="button" class="btn form-control" id="btn1">
    </div>
    <div class="col-md-6">
        <input type="button" class="btn form-control" id="btn2">
    </div>
</div>
like image 24
Mark Dibeh Avatar answered Sep 28 '22 06:09

Mark Dibeh


The easiest way in most situations is margin.

Where you can do :

button{
  margin: 13px 12px 12px 10px;
}

OR

button{
  margin: 13px;
}
like image 36
Gammer Avatar answered Sep 28 '22 06:09

Gammer


Dragan B. solution is correct. In my case I needed the buttons to be spaced vertically when stacking so I added the mb-2 property to them.

<div class="btn-toolbar">
   <button type="button" class="btn btn-primary mr-2 mb-2">First</button>
   <button type="button" class="btn btn-primary mr-2 mb-2">Second</button>
   <button type="button" class="btn btn-primary mr-2 mb-2">Third</button>
</div>
like image 41
Duilio Avatar answered Sep 28 '22 07:09

Duilio


Here's another approach based on the documentation.

 <div class="d-grid gap-2 d-md-flex" >
    <button type="button" class="btn btn-outline-primary btn-sm">button1</button>
    <button type="button" class="btn btn-outline-primary btn-sm">button2</button>
 </div>
like image 33
Illep Avatar answered Sep 28 '22 07:09

Illep


I used the Bootstrap 4 buttons plugin (https://getbootstrap.com/docs/4.0/components/buttons/#button-plugin) and added the class rounded to the labels and the class mx-1 to the middle button to achieve the desired look and feel of separate radio buttons. Using the class btn-toolbar made the radio button circles appear for me which is not what I wanted. Hope this helps someone.

        <div class="btn-group btn-group-toggle" data-toggle="buttons">
            <label class="btn btn-secondary active rounded">
                <input type="radio" name="options" id="option1" autocomplete="off" checked> Active
            </label>
            <label class="btn btn-secondary rounded mx-1">
                <input type="radio" name="options" id="option2" autocomplete="off"> Radio
            </label>
            <label class="btn btn-secondary rounded">
                <input type="radio" name="options" id="option3" autocomplete="off"> Radio
            </label>
        </div>
like image 31
Jonathan Avatar answered Sep 28 '22 06:09

Jonathan


Another way to achieve this is to add a class .btn-space in your buttons

  <button type="button" class="btn btn-outline-danger btn-space"
  </button>
  <button type="button" class="btn btn-outline-primary btn-space"
  </button>

and define this class as follows

.btn-space {
    margin-right: 15px;
}
like image 43
Swapnil Avatar answered Sep 28 '22 06:09

Swapnil