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

前端 未结 12 2453
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 12:21

What is the best way to horizontally space Bootstrap buttons?

At the moment the buttons are touching:

相关标签:
12条回答
  • 2020-12-12 12:44

    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>
    
    0 讨论(0)
  • 2020-12-12 12:44

    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;
    }
    
    0 讨论(0)
  • 2020-12-12 12:49

    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>

    0 讨论(0)
  • 2020-12-12 12:49

    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.

    0 讨论(0)
  • 2020-12-12 12:49

    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>
    
    0 讨论(0)
  • 2020-12-12 12:50

    I ended up doing something similar to what mark dibe did, but I needed to figure out the spacing for a slightly different manner.

    The col-x classes in bootstrap can be an absolute lifesaver. I ended up doing something similar to this:

    <div class="row col-12">
        <div class="col-3">Title</div>
    </div>
    <div class="row col-12">
        <div class="col-3">Bootstrap Switch</div>
    <div>
    

    This allowed me to align titles and input switches in a nicely spaced manner. The same idea can be applied to the buttons and allow you to stop the buttons from touching.

    (Side note: I wanted this to be a comment on the above link, but my reputation is not high enough)

    0 讨论(0)
提交回复
热议问题