css - Bootstrap 组水平输入

标签 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”值的第二个输入为固定宽度。但第一个输入和按钮具有固定宽度。

最佳答案

试试这个

<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

关于css - Bootstrap 组水平输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863342/

相关文章:

css - Safari (Win7) 不使用 max-height 属性刷新 img 高度

css - 我正在尝试将我的 SCSS 代码编译成 CSS,但未找到变量

css - Bootstrap : How to create a series of div on one line hiding the overflowing divs

html - 导致导航栏元素落在导航栏之外的汉堡菜单

jquery - 让 Jquery 和 Bootstrap 与 Rails 6 配合使用

css - 我怎样才能居中这个 DIV (CSS/HTML)

jquery - 通过 CSS 隐藏 HTML 表格中的列

javascript - jQuery scrollTop 值是什么意思?

css - Bootstrap 表格标题颜色仅在单元格悬停时显示

html - 当 Bootstrap Modal 打开时,滚动条会改变方向