Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space between Bootstrap 3 buttons

If I put several Bootstrap 3 buttons in a row:

    <button class="btn btn-default">Button 1</button>
    <button class="btn btn-default">Button 2</button>
    <button class="btn btn-default">Button 3</button>

there is a small space between them. Where does it come from and how to remove it without using float? According to the Firebug and Chrome Inspector the buttons haven't any margin applied to them.

like image 792
Nikola Obreshkov Avatar asked May 02 '15 22:05

Nikola Obreshkov


2 Answers

The newline between the buttons actually causes the space. Observe:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>

<button class="btn btn-default">Button 1</button><button class="btn btn-default">Button 2</button><button class="btn btn-default">Button 3</button>

There is a button-group rule you can use if you want the buttons visually grouped: http://getbootstrap.com/components/#btn-groups

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group" role="group" aria-label="...">
  <button type="button" class="btn btn-default">Left</button>
  <button type="button" class="btn btn-default">Middle</button>
  <button type="button" class="btn btn-default">Right</button>
</div>
like image 57
Tieson T. Avatar answered Oct 04 '22 00:10

Tieson T.


I believe you style your buttons display:inline-block; or inline. By default they create spaces if you have newline character.

So to remove it, put those markups next to each other without newline char. It would get messy, but will get what you want without having a style float

So do it like this :

<button class="btn btn-default">Button 1</button><button class="btn btn-default">Button 2</button><button class="btn btn-default">Button 3</button>
like image 22
David Escudero Avatar answered Oct 04 '22 02:10

David Escudero