twitter-bootstrap 引导表单组间距
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23614338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bootstrap form-group spacing
提问by Srik
I would like to have some spacing between the controls. According to spec, it should be achieved using form-group class. However it is not working in my case.
我希望控件之间有一些间距。根据规范,应该使用表单组类来实现。但是,它在我的情况下不起作用。
<div class="col-xs-12 col-sm-12">
<form role="form">
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpTitle">Title</label>
</div>
<div class="col-xs-9">
<input type="text" class="form-control" placeholder="Title of the program" id="cpTitle" />
</div>
</div>
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpDesc">Description</label>
</div>
<div class="col-xs-9">
<textarea class="form-control" rows="3" placeholder="Description of the program" id="cpDesc"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpAddr">Program address</label>
</div>
<div class="col-xs-9">
<input type="text" class="form-control" placeholder="Name of Facility" id="cpAddr" />
<input type="text" class="form-control" placeholder="Street 1" />
<input type="text" class="form-control" placeholder="Street 2" />
<div class="col-xs-4">
<input type="text" class="form-control" placeholder="State" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" placeholder="City" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" placeholder="Zip" />
</div>
</div>
</div>
</form>
</div>
回答by Daniel Broughan
Main issue is to make sure you set class "form-horizontal" on your form. For the program address fields, you could either set out a separate row for each or what I'd suggest is just adding a css for margin-bottom on each input field. Edited jsfiddle above
主要问题是确保您在表单上设置类“表单水平”。对于程序地址字段,您可以为每个字段设置一个单独的行,或者我建议只是在每个输入字段上为 margin-bottom 添加一个 css。上面编辑了 jsfiddle
.margin-bottom {
margin-bottom:15px;}
<div class="col-xs-12 col-sm-12">
<form role="form" class='form-horizontal'>
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpTitle">Title</label>
</div>
<div class="col-xs-9">
<input type="text" class="form-control" placeholder="Title of the program" id="cpTitle" />
</div>
</div>
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpDesc">Description</label>
</div>
<div class="col-xs-9">
<textarea class="form-control" rows="3" placeholder="Description of the program" id="cpDesc"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-3 text-right">
<label for="cpAddr">Program address</label>
</div>
<div class="col-xs-9">
<input type="text" class="form-control margin-bottom" placeholder="Name of Facility" id="cpAddr" />
<input type="text" class="form-control margin-bottom" placeholder="Street 1" />
<input type="text" class="form-control margin-bottom" placeholder="Street 2" />
</div>
</div>
<div class="form-group">
<div class="col-xs-3 text-right"> </div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="State" />
</div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="City" />
</div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder="Zip" />
</div>
</div>
</form>

