我也在努力解决同样的问题。我使用的bootstrap类不适合我。我想出了一个解决方法,如下所示:
<form action='...' method='POST' class='form-group'> <div class="form-horizontal"> <input type="text" name="..." class="form-control" placeholder="Search People..." style="width:280px;max-width:280px;display:inline-block"/> <button type="submit" class="btn btn-primary" style="margin-left:-8px;margin-top:-2px;min-height:36px;"> <i class="glyphicon glyphicon-search"></i> </button> </div> </form>
基本上,我覆盖了“form-control”类的display属性,并使用其他样式属性来校正大小和位置。
以下是结果:
使用 的 .FORM内联 强> =这将左对齐标签和内联块控件,以实现紧凑的布局 例: http://jsfiddle.net/hSuy4/292/
<div class="form-inline"> <input type="text"> <input type="button" class="btn" value="submit"> </div>
的 .FORM水平 强> =右对齐标签并将它们浮动到左侧,使它们与控件显示在同一行上,这对于2列表单布局更好。
(e.g. Label 1: [textbox] Label 2: [textbox] : [button] )
例子: http://twitter.github.io/bootstrap/base-css.html#forms
style="padding-top: 8px"
使用它可以在你的行中向上或向下移动你的div。为我创造奇迹。
只是抬头,似乎有一个特殊的CSS类为此调用 form-horizontal
form-horizontal
input-append有另一个副作用,它将font-size降为零
如@abimelex的答案所示,输入和按钮可以使用 .input-group 课程(见 http://getbootstrap.com/components/#input-groups-buttons ):
.input-group
<div class="input-group"> <span class="input-group-btn"> <button class="btn btn-default" type="button">Go!</button> </span> <input type="text" class="form-control"> </div>
<div class="input-group"> <input type="text" class="form-control"> <span class="input-group-btn"> <button class="btn btn-default" type="button">Go!</button> </span> </div>
已添加此解决方案以使我的答案保持最新,但请坚持您的投票 @abimelex提供的答案 。
Bootstrap提供了一个 .input-append class,作为包装元素,并为您纠正:
.input-append
<div class="input-append"> <input name="search" id="search"/> <button class="btn">button</button> </div>
正如@OleksiyKhilkevich在他的回答中指出的那样,还有第二种方法可以对齐 input 和 button 通过使用 .form-horizontal 类:
input
button
.form-horizontal
<div class="form-horizontal"> <input name="search" id="search"/> <button class="btn">button</button> </div>
这两个类之间的区别在于 .input-append 将放置 button 反对 input 元素(所以它们看起来像是附着在一起),在哪里 .form-horizontal 会在它们之间留一个空格。
- 注意 -
允许的 input 和 button 元素彼此相邻而没有间距, font-size 已经设定为 0 在里面 .input-append class(这将删除之间的白色间距) inline-block 元件)。这可能会对字体大小产生负面影响 input element如果要使用覆盖默认值 em 要么 % 测量。
font-size
0
inline-block
em
%
我首先尝试过并最终得到一些我想分享的变化。这是适用于我的代码(查找附带的屏幕截图):
<div class="input-group"> <input type="text" class="form-control" placeholder="Search text"> <span class="input-group-btn" style="width:0;"> <button class="btn btn-default" type="button">Go!</button> </span> </div>
如果你想看到它工作,只需在你的编辑器中使用下面的代码:
<html> <head> <link type='text/css' rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css' /> </head> <body> <div class="container body-content"> <div class="form-horizontal"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search text"> <span class="input-group-btn" style="width:0;"> <button class="btn btn-default" type="button">Go!</button> </span> </div> </div> </div> </body> </html>
希望这可以帮助。
<form class="form-inline"> <div class="form-group"> <label class="sr-only" for="exampleInputEmail3">Email address</label> <input type="email" class="form-control" id="exampleInputEmail3" placeholder="Email"> </div> <button type="submit" class="btn btn-default">Sign in</button> </form>
我尝试了以上所有代码,但没有一个修复我的问题。这对我有用。我使用了input-group-addon。
<div class = "input-group"> <span class = "input-group-addon">Go</span> <input type = "text" class = "form-control" placeholder="you are the man!"> </div>
没有直接相关,除非你有类似的代码,但我只是注意到一个奇怪的行为形式 - 内联,bootstrap 3.3.7
我没有使用行和单元格,因为它是一个桌面项目,如果开始标记在表格下面(在这种情况下):
<table class="form-inline"> <form> <tr>
表单元素将堆叠。
切换并正确排列。
<form> <table class="form-inline"> <tr>
Safari 10.0.2和最新的Chrome没有任何区别。也许我的布局错了,但不是很宽容。