将输入字段对齐到 Bootstrap3 中按钮工具栏的左侧
Aligning input field to left of button toolbar in Bootstrap3
我试图将我的输入字段直接放在右侧的 3 个按钮(btn-toolbar
)的左侧。我不确定为什么这如此困难。我曾尝试更改输入字段的宽度并使用各种实用程序 类 但没有成功。任何帮助将不胜感激。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-2">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-sm-6">
<label class="control-label"> </label>
<input type="search" class="form-control"/>
<div class="pull-right">
<label class="control-label"> </label>
<div class="btn-toolbar">
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
</div>
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
在一行中,您的列必须加起来为 12,因为它是 Bootstrap 中的 12 列网格。我将输入设为 2 列,将按钮设为 4 列。
我还通过添加 3 列 4 后跟 2 列 6 并在输入字段周围添加 'form group' class 来修复移动尺寸布局。
已更新以将 'text-right' 添加到按钮列,并从三个按钮周围删除 'button-toolbar'。
再次更新,添加更多断点,大屏更好看。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2 col-lg-1 text-right">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-xs-6 col-sm-2 col-md-2 col-lg-3 col-md-offset-1 col-lg-offset-2">
<div class="form-group">
<label class="control-label"> </label>
<input type="search" class="form-control"/>
</div>
</div>
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-right">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
在@k123 的帮助下,我想出了一个似乎工作正常的解决方案。但是如果有更好的方法来完成这个,我很乐意选择一个更好的答案。
我最终将 form-group
放入最后一个 div
并使用 pull-left
class 将其强制放在按钮的左侧。这绝对不是最理想的解决方案,但在大型显示器上看起来“足够好”。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-xs-6 col-sm-2">
</div>
<div class="col-xs-6 col-sm-4 text-right">
<div class="form-group pull-left">
<label class="control-label"> </label>
<input type="search" class="form-control" />
</div>
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
我试图将我的输入字段直接放在右侧的 3 个按钮(btn-toolbar
)的左侧。我不确定为什么这如此困难。我曾尝试更改输入字段的宽度并使用各种实用程序 类 但没有成功。任何帮助将不胜感激。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-2">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-sm-6">
<label class="control-label"> </label>
<input type="search" class="form-control"/>
<div class="pull-right">
<label class="control-label"> </label>
<div class="btn-toolbar">
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
</div>
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
在一行中,您的列必须加起来为 12,因为它是 Bootstrap 中的 12 列网格。我将输入设为 2 列,将按钮设为 4 列。
我还通过添加 3 列 4 后跟 2 列 6 并在输入字段周围添加 'form group' class 来修复移动尺寸布局。
已更新以将 'text-right' 添加到按钮列,并从三个按钮周围删除 'button-toolbar'。
再次更新,添加更多断点,大屏更好看。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2 col-lg-1 text-right">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-xs-6 col-sm-2 col-md-2 col-lg-3 col-md-offset-1 col-lg-offset-2">
<div class="form-group">
<label class="control-label"> </label>
<input type="search" class="form-control"/>
</div>
</div>
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-right">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
在@k123 的帮助下,我想出了一个似乎工作正常的解决方案。但是如果有更好的方法来完成这个,我很乐意选择一个更好的答案。
我最终将 form-group
放入最后一个 div
并使用 pull-left
class 将其强制放在按钮的左侧。这绝对不是最理想的解决方案,但在大型显示器上看起来“足够好”。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">Start Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<div class="form-group">
<label class="control-label">End Date</label>
<div>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="col-xs-4 col-sm-2">
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Get Data</button>
</div>
</div>
<div class="col-xs-6 col-sm-2">
</div>
<div class="col-xs-6 col-sm-4 text-right">
<div class="form-group pull-left">
<label class="control-label"> </label>
<input type="search" class="form-control" />
</div>
<label class="control-label"> </label>
<div>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-success">Create</button>
<button type="button" class="btn btn-danger">Close</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>