bootstrap组水平输入

时间:2015-06-16 09:12:10

标签: css twitter-bootstrap

我有一个多行表单,在其中一行中我想使用bootstrap水平分组两个输入和一个按钮。 JSFIDDLE

<form>
<div class="form-group">
    <lable>first :</lable>
    <div class="input-group">
        <input type="text" class="form-control" value="123" style="width:50px;"/> <span class="input-group-btn"
                                                                                        style="width:0px;"></span>

        <input type="text" class="form-control" value="test2" disabled/>
    </div>
</div>
<div class="form-group">
    <lable>second :</lable>
    <div class="input-group">
        <input type="text" class="form-control" value="123" style="width:50px;"/> <span class="input-group-btn"
                                                                                        style="width:0px;"></span>

        <input type="text" class="form-control" value="test2" disabled/> <span class="input-group-btn">
    <button class="btn btn-primary" type="button">...</button>
</span>

    </div>
</div>

问题是输入之间的空白区域: enter image description here

如何在没有空间的情况下并排排列输入和按钮?

更新 我不希望具有'test2'值的第二个输入是固定宽度。但是第一个输入和具有固定宽度的按钮。

3 个答案:

答案 0 :(得分:0)

您可以在包含按钮的其他输入和跨度上定义宽度,如下所示:

<form>
    <div class="form-group">
        <lable>first :</lable>
        <div class="input-group">
            <input type="text" class="form-control" value="123" style="width:50px;" />
            <span class="input-group-btn" style="width:0px;"></span>
            <input type="text" class="form-control" value="test2" disabled/>
        </div>
    </div>
    <div class="form-group">
        <lable>second :</lable>
        <div class="input-group">
            <input type="text" class="form-control" value="123" style="width:50px;" />
            <input type="text" class="form-control" value="test2" style="width:150px;" disabled /> 
            <span class="input-group-btn" style="width:50px;">
                <button class="btn btn-primary" type="button">...</button>
            </span>
        </div>
    </div>
<form>

<强>更新: 不需要固定宽度的解决方案

input-group-field

Jsfiddle for input-group-field

答案 1 :(得分:0)

只需在您的css文件中添加

.input-group-btn {
width:0;

}

此工作JSFIDDLE

答案 2 :(得分:0)

试试这个

<div class="form-wrapper">
    <form class="form-inline" role="form">
        <div class="form-group  fixed-width-group">
            <input type="email" class="form-control fixed-width-input" id="ejemplo_email_2" placeholder="123">
        </div>
        <div class="form-group  fluid-width-group">
            <input type="password" class="form-control fluid-width-input" id="ejemplo_password_2" placeholder="Test2">
        </div>
       <button type="submit" class="btn my-btn">...</button>
    </form>
</div>

.form-wrapper {
    text-align: center;
    padding: 20px;
}
.form-inline {
    height: 34px;
}
.form-inline .form-control {
    width: 100%;
}
.form-inline .form-group {
    margin-bottom: 0;
    float: left;
}
.form-inline .fixed-width-group {
    width: 100px;
    border-radius: 4px 0 0 4px;

.form-inline .fluid-width-group {
    width: calc(100% - 200px);
    border-radius: 0;
}
.form-inline .fixed-width-input {
    border-radius: 4px 0 0 4px;
 }
.form-inline .fluid-width-input {
    border-radius: 0;
}
.my-btn {
    text-transform: uppercase;
    height: 100%;
    border-radius: 0 4px 4px 0;
    background-color: #35bfd1;
    float: right;
    color: #fff;
    padding: 5px 15px;
    width: 100px;
}
.my-btn:hover {
    color: #fff;
    background-color: #31b0d5;
}
.fluid-width-input {
    border-radius: 0;
}

There is a jsfiddle example to play wiht

另外看看这个答案,也许你觉得它很有用:

https://stackoverflow.com/questions/30854719/achieving-horizontal-inline-form-for-signup-in-bootstrap/30856980#30856980