简体   繁体   English

如何在引导程序中将div与类右拉垂直居中对齐

[英]How to align the div with class pull-right vertically center in bootstrap

I want to create a form line with a label an input field and a button. 我想创建一个带有标签的表单行,输入字段和按钮。 The first two element should be align left the button should be aligned right. 前两个元素应该左对齐,按钮应该对齐。 I've tried the pull-right class, but it ruins the vertical alignment of the button. 我已经尝试了右拉类,但它破坏了按钮的垂直对齐方式。 I want it to be vertically centered. 我希望它垂直居中。 I've tried to set the line-height, but it ruins the vertical alignment of the label. 我试图设置行高,但它会破坏标签的垂直对齐方式。 (I want the label to be aligned vertically center relative to the input too) (我希望标签也相对于输入垂直对齐)

<form class="form-horizontal">
   <div class="form-group col-sm-11">
       <label for="inputEmail3" class="col-sm-1 control-label">Email</label>
       <div class="col-sm-3">
           <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
       </div>
   </div>
   <div class="pull-right">
        <button>Add</button>
   </div>
</form>

http://plnkr.co/edit/i8jmEowKaKOcM2P8N225?p=preview http://plnkr.co/edit/i8jmEowKaKOcM2P8N225?p=preview

在此输入图像描述

As mentioned in the comments: To display multiple form elements in one row, use the form-inline class. 如注释中所述:要在一行中显示多个表单元素,请使用form-inline类。 This applies to forms within viewports that are at least 768px wide (so watch the example below in full screen to see the effect). 这适用于视口中至少为768像素宽的表单(因此请在全屏幕中观看下面的示例以查看效果)。

See Bootstraps documentation for more information. 有关更多信息,请参阅Bootstraps文档

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <form class="form-inline"> <div class="form-group"> <label for="inputEmail3">Email</label> <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> </div> <div class="pull-right"> <button class="btn btn-default">Add</button> </div> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM