形式内联内的形式水平在twitter bootstrap?

在没有任何自制类的情况下,在twitter bootstrap中设计一个看起来像这样的表单(请参阅下面的链接)的最佳方法是什么?

是否可以像下面的例子一样,在一个水平的表单中设置一个内联的内部表单:

截图of UI goal

474825 次浏览

不要嵌套<form>标签,这将不起作用。只需要使用Bootstrap类。

引导3

<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputType" class="col-md-2 control-label">Type</label>
<div class="col-md-3">
<input type="text" class="form-control" id="inputType" placeholder="Type">
</div>
</div>
<div class="form-group">
<span class="col-md-2 control-label">Metadata</span>
<div class="col-md-6">
<div class="form-group row">
<label for="inputKey" class="col-md-1 control-label">Key</label>
<div class="col-md-2">
<input type="text" class="form-control" id="inputKey" placeholder="Key">
</div>
<label for="inputValue" class="col-md-1 control-label">Value</label>
<div class="col-md-2">
<input type="text" class="form-control" id="inputValue" placeholder="Value">
</div>
</div>
</div>
</div>
</form>

你可以通过多种方式实现这种行为,这只是一个例子。在bootp上测试它

引导2

<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputType">Type</label>
<div class="controls">
<input type="text" id="inputType" placeholder="Type">
</div>
</div>
<div class="control-group">
<span class="control-label">Metadata</span>
<div class="controls form-inline">
<label for="inputKey">Key</label>
<input type="text" class="input-small" placeholder="Key" id="inputKey">
<label for="inputValue">Value</label>
<input type="password" class="input-small" placeholder="Value" id="inputValue">
</div>
</div>
</form>

注意,我使用.form-inline来获得.controls内部的propper样式 你可以在 jsfiddle

上测试它

对于上面的3个例子,bootstrap工作,但过于复杂,而不是使用form-group,使用form-inline的字段,你想内联。

例如:

<div class="form-group">
<label>CVV</label>
<input type="text" size="4" class="form-control" />
</div>


<div class="form-inline">
<label>Expiration (MM/YYYY)</label><br>
<input type="text" size="2" class="form-control" /> / <input type="text" size="4" class="form-control" />
</div>

这使用推特引导3。X和一个CSS类来获得标签位于输入的顶部。这里是小提琴的链接,确保将结果面板扩展到足够宽以看到效果。

HTML:

  <div class="row myform">
<div class="col-md-12">
<form name="myform" role="form" novalidate>
<div class="form-group">
<label class="control-label" for="fullName">Address Line</label>
<input required type="text" name="addr" id="addr" class="form-control" placeholder="Address"/>
</div>


<div class="form-inline">
<div class="form-group">
<label>State</label>
<input required type="text" name="state" id="state" class="form-control" placeholder="State"/>
</div>


<div class="form-group">
<label>ZIP</label>
<input required type="text" name="zip" id="zip" class="form-control" placeholder="Zip"/>
</div>
</div>


<div class="form-group">
<label class="control-label" for="country">Country</label>
<input required type="text" name="country" id="country" class="form-control" placeholder="country"/>
</div>
</form>
</div>
</div>

CSS:

.myform input.form-control {
display: block;  /* allows labels to sit on input when inline */
margin-bottom: 15px; /* gives padding to bottom of inline inputs */
}

我知道这是一个老答案,但我通常是这样做的:

CSS:

.form-control-inline {
width: auto;
float:left;
margin-right: 5px;
}

然后将你想要内联的字段包装在div中,并在输入中添加.form-control-inline,示例:

超文本标记语言

<label class="control-label">Date of birth:</label>
<div>
<select class="form-control form-control-inline" name="year"> ... </select>
<select class="form-control form-control-inline" name="month"> ... </select>
<select class="form-control form-control-inline" name="day"> ... </select>
</div>

为了简化,只需在输入前添加class="form-inline"

例子:

<div class="col-md-4 form-inline"> //add the class here...
<label>Lot Size:</label>
<input type="text" value="" name="" class="form-control" >
</div>

自引导4使用div class="form-row"结合div class="form-group col-X"。X是你需要的宽度。你会得到很好的内联列。看到小提琴

<form class="form-horizontal" name="FORMNAME" method="post" action="ACTION" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2" for="naam">Naam:&nbsp;*</label>
<div class="col-sm-10">
<input type="text" require class="form-control" id="naam" name="Naam" placeholder="Uw naam" value="{--NAAM--}" >
<div id="naamx" class="form-error form-hidden">Wat is uw naam?</div>
</div>
</div>


<div class="form-row">


<div class="form-group col-5">
<label class="control-label col-sm-4" for="telefoon">Telefoon:&nbsp;*</label>
<div class="col-sm-12">
<input type="tel" require class="form-control" id="telefoon" name="Telefoon" placeholder="Telefoon nummer" value="{--TELEFOON--}" >
<div id="telefoonx" class="form-error form-hidden">Wat is uw telefoonnummer?</div>
</div>
</div>


<div class="form-group col-5">
<label class="control-label col-sm-4" for="email">E-mail: </label>
<div class="col-sm-12">
<input type="email" require class="form-control" id="email" name="E-mail" placeholder="E-mail adres" value="{--E-MAIL--}" >
<div id="emailx" class="form-error form-hidden">Wat is uw e-mail adres?</div>
</div>
</div>


</div>


<div class="form-group">
<label class="control-label col-sm-2" for="titel">Titel:&nbsp;*</label>
<div class="col-sm-10">
<input type="text" require class="form-control" id="titel" name="Titel" placeholder="Titel van uw vraag of aanbod" value="{--TITEL--}" >
<div id="titelx" class="form-error form-hidden">Wat is de titel van uw vraag of aanbod?</div>
</div>
</div>
<from>