简体   繁体   English

是否可以使用Bootstrap将多个控制组放在一行中

[英]is it possible to have multiple control-group in one row with Bootstrap

I am using Bootstrap for creating a simple webpage. 我正在使用Bootstrap来创建一个简单的网页。 When I create a form containing some personal information, like first name, last name, email address, etc. Sometimes I prefer to make 2 control group (first name label & input field, and last name label & input field) in the same row. 当我创建一个包含一些个人信息的表单时,如姓名,姓氏,电子邮件地址等。有时我更喜欢在同一行中创建2个控制组(名字标签和输入字段,以及姓氏标签和输入字段) 。 How can I achieve it ? 我怎样才能实现它? It's not evident to do it in the Horizontal-form . 水平形式进行此操作并不明显。 Thanks for your help ! 谢谢你的帮助 !

You can't do that with horizontal form, you must use .form-inline Twitter Bootstrap class . 你不能用横向形式做到这一点,你必须使用.form-inline Twitter Bootstrap类

<form class="form-inline">
    <label>First name</label>
    <input type="text" class="input-small" placeholder="First name"/>
    <label>Last name</label>
    <input type="text" class="input-small" placeholder="Last name"/>
</form>

http://jsfiddle.net/fq4wm/ http://jsfiddle.net/fq4wm/

Or, you can do that also in horizontal form, but you must to override many classes and properties, and I'll not recommend that. 或者,您也可以以横向形式执行此操作,但您必须覆盖许多类和属性,我不建议这样做。 Better way is to use default Twitter Bootstrap classes for this stuff. 更好的方法是使用默认的Twitter Bootstrap类来完成这些工作。

EDIT: You can combine horizontal and inline classes inside one form like this: 编辑:您可以在一个窗体中组合水平和内联类,如下所示:

<form class="form-inline">
    <label>First name</label>
    <input type="text" class="input-small" placeholder="First name"/>
    <label>Last name</label>
    <input type="text" class="input-small" placeholder="Last name"/>
    <br/><br/><br/>
    <div class="form-horizontal">
        <div class="control-group">
            <label class="control-label" for="inputEmail">Email</label>
            <div class="controls">
                <input type="text" id="inputEmail" placeholder="Email"/>
            </div>
        </div>
        <div class="control-group">
           <label class="control-label" for="inputPassword">Password</label>
           <div class="controls">
               <input type="password" id="inputPassword" placeholder="Password"/>
           </div>
         </div>
     </div>
</form>

http://jsfiddle.net/fq4wm/6/ http://jsfiddle.net/fq4wm/6/

Change the class to make it an inline form: 更改类以使其成为内联形式:

<form class="form-inline">
   ...
</form>

Then it's easier to place fields in different rows and columns. 然后,将字段放在不同的行和列中会更容易。

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

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