【问题标题】:bootstrap group inputs horizontally水平引导组输入
【发布时间】:2015-09-01 00:30:52
【问题描述】:

我有一个多行表单,我想在其中一行中使用引导程序将两个输入和一个按钮水平分组。 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>

问题是输入之间的空白:

如何在没有空格的情况下并排对齐输入和按钮?

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

【问题讨论】:

    标签: css twitter-bootstrap


    【解决方案1】:

    试试这个

    <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

    【讨论】:

    • tnx,但我不希望我的表单是内联的!我有多行表格。
    • @medusa,为什么你说表单是内联的,你的意思是 display: inline 因为它不是
    • 我在一个复杂的表单中有多个表单组(两个输入和按钮并排在一起)。我的意思是不在一行!
    • @medusa 看看这个jsfiddle.net/ma9g2oga,是一样的想法,我只是添加了更多的表单组,然后我放入了一个包装器(内容行),如果这不是你想要的,请放一张你想要的照片,我会尽力帮助你
    • 正是我想要的!非常感谢您的帮助!
    【解决方案2】:

    只需将其添加到您的 css 文件中

    .input-group-btn {
    width:0;
    

    }

    这个工作JSFIDDLE

    【讨论】:

    • tanx,但它使值为“test2”的输入为固定宽度。
    【解决方案3】:

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

    <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

    【讨论】:

    • 我不希望第二个输入值为“test2”的宽度固定。但第一个输入和按钮宽度固定。
    • 好的,那么这可能是有用的:参考:linkJSFiddle link
    • tanx,我试过了,但我无法使用 input-group-field 为我的代码修复它。
    猜你喜欢
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2013-09-08
    • 2014-06-25
    • 1970-01-01
    • 2014-08-16
    • 2019-03-28
    相关资源
    最近更新 更多