Html 使用 twitter bootstrap 将表单分为两列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19637861/
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
Dividing form into two columns with twitter bootstrap
提问by renathy
What is the correct way to style form
with bootstrapin the following scenario:
在以下情况下form
使用bootstrap进行样式设置的正确方法是什么:
I need to use fieldset (that will be styled later)
I need to divide
form
into two columnsEach column has label+control, some will have label+control1+control2 etc.
我需要使用字段集(稍后将对其进行样式设置)
我需要
form
分成两列每列都有标签+控制,有些会有标签+控制1+控制2等。
I am new to bootstrap. I have come to the following solution (jsfiddle).
我是引导程序的新手。我来到了以下解决方案 (jsfiddle)。
The question is: is this the correct way to do this?Does it not violate the bootstrap semantics?
问题是:这是正确的方法吗?它不违反引导语义吗?
I do not understand when to use form-group
, am I using it correctly?
我不明白什么时候使用form-group
,我使用正确吗?
Should I not include some class="row"
here for correct semantics?
我不应该在这里包含一些class="row"
正确的语义吗?
HTML:
HTML:
<div class="container">
... <some content here> ....
<form class="form-horizontal">
<fieldset>
<legend>Portfolio</legend>
<div class="col-xs-6">
<div class="form-group">
<label for="name" class="col-xs-4 control-label">Label1</label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="control1" />
</div>
</div>
<div class="form-group">
<label for="name" class="col-xs-4 control-label">label2</label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="control2" />
</div>
</div>
<div class="form-group">
<label for="name" class="col-xs-4 control-label">label3</label>
<div class="col-xs-8 form-inline">
<div class="form-group col-xs-6">
<input type="text" class="form-control" placeholder="control1" />
</div>
<div class="form-group col-xs-6">
<input type="text" class="form-control" placeholder="control2" />
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="name" class="col-xs-4 control-label">Label1</label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="control1" />
</div>
</div>
<div class="form-group">
<label for="name" class="col-xs-4 control-label">label2</label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="control2" />
</div>
</div>
</div>
</fieldset>
</form>
</div>
I have seen all Bootstrap form examples, but I do not get how to separate form
into two columns. I have also read the whole documentation, but I feel that this is not the right way how to use col
and other classes.
我看过所有 Bootstrap 表单示例,但我不知道如何form
分成两列。我也阅读了整个文档,但我觉得这不是如何使用col
和其他类的正确方法。
回答by Itay Moav -Malimovka
Column separation happens inside container
elements.
Each time you have an element you want to do grid inside it, give it class="container"
and in it u can use the normal row
and column
classes.
列分离发生在container
元素内部。
每次你有一个元素想要在其中做网格时,给它class="container"
并在其中你可以使用普通row
和column
类。
Also check Bootstrap's out of the box form styles.
还要检查 Bootstrap 的开箱即用的表单样式。
Below are the bare bones, add on to it what u need (like text align etc)
下面是裸露的骨头,添加你需要的东西(比如文本对齐等)
<form class="container">
<div class="row">
<div class="col-md-3">
<label for="username" class="control-label">label</label>
</div>
<div class="col-md-3">
<input type="text" name="username" class="form-control" placeholder="Email address" autofocus>
</div>
<div class="col-md-3">
<label for="username" class="control-label">label</label>
</div>
<div class="col-md-3">
<input type="text" name="username" class="form-control" placeholder="Email address" autofocus>
</div>
</div>
</form>