Bootstrap 3按钮组和输入组在一行中

时间:2013-09-18 12:46:39

标签: css twitter-bootstrap html css-float

如果您查看以下示例,您可以看到输入组位于按钮组下方:

http://bootply.com/81723

我已经尝试将两个组都放入浮动div中,但浏览器仍然会破坏该行。 我注意到“.btn-group,.btn-group-vertical”包含“display:inline-block”。注释掉这一行之后,行没有中断,但是我没有两个div之间的空格(虽然我想通过“padding-right:16px”得到一个)

2 个答案:

答案 0 :(得分:15)

使用容器的表格显示找到了一个可行的解决方案:

<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;
  }
}

答案 1 :(得分:4)

怎么样

<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>

你需要手动折叠边框,并在悬停和签入空间时调整它们:

.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;
}