Bootstrap 3 button-group and input-group in one row

33,800

Solution 1

Found a working solution using table-display for containers:

<div class="Toolbar">
<div>
    <div class="btn-group">
        <button id="ButtonCreate" class="btn btn-default btn-sm" onclick="CreateItem()" title="Erstellen"><span class="glyphicon glyphicon-file"></span></button>
        <button id="ButtonUpdate" class="btn btn-default btn-sm" onclick="UpdateItem()" title="Bearbeiten"><span class="glyphicon glyphicon-pencil"></span></button>
        <button id="ButtonDelete" class="btn btn-default btn-sm" onclick="DeleteItems()" title="L&ouml;schen"><span class="glyphicon glyphicon-trash"></span></button>
        <button id="ButtonExport" class="btn btn-default btn-sm" onclick="ExportItems()" title="Exportieren"><span class="glyphicon glyphicon-export"></span></button>
    </div>
</div>

<div>
    <div class="input-group input-group-sm">
        <span class="input-group-btn"><button id="ButtonSearch" class="btn btn-default btn-sm" onclick="SearchItem()" title="Suchen"><span class="glyphicon glyphicon-search"></span></button></span>
        <input type="text" class="form-control" style="width: 300px;" placeholder="Suchen">
    </div>
</div>
</div>

CSS (LESS):

.Toolbar
{
  position: relative;
  display: table;
}

.Toolbar > div
{
  display: table-cell;
  padding-right: 8px;
  vertical-align: top;
}

.Toolbar
{
  .btn-group, .btn-group-vertical
  {
    vertical-align: inherit;
  }
}

Solution 2

How about

<div class="input-group input-group-sm">
  <span class="input-group-btn btn-group-custom">
    <button id="ButtonCreate" class="btn btn-default btn-sm" onclick="CreateItem()" title="Erstellen"><span class="glyphicon glyphicon-file"></span></button>
    <button id="ButtonUpdate" class="btn btn-default btn-sm" onclick="UpdateItem()" title="Bearbeiten"><span class="glyphicon glyphicon-pencil"></span></button>
    <button id="ButtonDelete" class="btn btn-default btn-sm" onclick="DeleteItems()" title="Löschen"><span class="glyphicon glyphicon-trash"></span></button>
    <button id="ButtonExport" class="btn btn-default btn-sm" onclick="ExportItems()" title="Exportieren"><span class="glyphicon glyphicon-export"></span></button>
    <button id="ButtonSearch" class="btn btn-default btn-sm" onclick="SearchItem()" title="Suchen"><span class="glyphicon glyphicon-search"></span></button>
  </span>
  <input class="form-control" style="width: 300px;" placeholder="Suchen" type="text">
</div>

You need to manually collapse borders and tweek them on hover and for the visaul space:

.btn-group-custom .btn {
  border-right-width: 0;
}
.btn-group-custom .btn:hover {
  border-right-width: 1px;
}
.btn-group-custom .btn:hover + .btn {
  border-left-width: 0;
}
#ButtonSearch {
  border-left-width: 1px;
  border-right-width: 0;
  margin-left: 16px;
}
#ButtonExport {
  border-right-width: 1px;
}
Share:
33,800
IT KFV
Author by

IT KFV

Updated on November 07, 2020

Comments

  • IT KFV
    IT KFV over 3 years

    If you have a look at the following example, you can see that the input-group is below the button-group:

    http://bootply.com/81723

    I already tried putting both groups into floating divs, but the browsers still break the row. I noticed that ".btn-group, .btn-group-vertical" contain a "display: inline-block". After commenting this line out, the row doesn't break, but I don't have a space between both div (although I thought to get one by "padding-right: 16px")

  • IT KFV
    IT KFV over 10 years
    Would be a possibility, but I want to have an visual division between the buttons and the search field
  • IT KFV
    IT KFV over 10 years
    Thank you, but there I have to restyle the Search button (round corners,..) and I want to let bootstrap do this (thinking of override some bootstrap css on a central place); due to the fact I can't answer my question within 8 hours, I'll post my solution (using inline-block) tomorrow