Bootstrap:如何将按钮组居中对齐(垂直)
Posted
技术标签:
【中文标题】Bootstrap:如何将按钮组居中对齐(垂直)【英文标题】:Bootstrap: How to align the button group in the center (vertically) 【发布时间】:2016-09-01 13:34:11 【问题描述】:在以下代码中:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified javascript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading"><h2>Element Selection</h2></div>
<div class="panel-body">
<div class="row">
<div class="col-lg-5">
<div class="form-group">
<h3><span class="label label-info">Element Segment</span></h3>
<textarea class="form-control" rows="8"></textarea>
</div>
</div>
<div class="col-lg-2 text-center" >
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">>></button>
<button type="button" class="btn btn-primary"><<</button>
<button type="button" class="btn btn-primary">ALL>></button>
<button type="button" class="btn btn-primary"><< ALL</button>
</div>
</div>
<div class="col-lg-5">
<div class="form-group">
<h3><span class="label label-success">Element Segment</span></h3>
<textarea class="form-control" rows="8"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
现在结果如下:
所以我可以将按钮组垂直放置在中心位置。我搜索并尝试了vertical-align: middle
,但它对我不起作用。
【问题讨论】:
查看这里:***.com/questions/20547819/… 如果你能给该行一个 id,我会这样做:bootply.com/87KkKmPmqK 【参考方案1】:您可以将Flexbox
与媒体查询DEMO 一起使用(1200px
用于.col-lg-
)
@media(min-width: 1200px)
.flex-row
display: flex;
align-items: center;
【讨论】:
【参考方案2】:@Nenad Vracar 已经发布了答案,但您也可以试试这个
.flex-row
display: flex;
align-items: center;
DEMO HERE
【讨论】:
以上是关于Bootstrap:如何将按钮组居中对齐(垂直)的主要内容,如果未能解决你的问题,请参考以下文章
将 div 与 Bootstrap 列中的相邻 div 对齐