Bootstrap内联表单按钮对齐

时间:2014-02-28 17:59:34

标签: jquery html css twitter-bootstrap jquery-plugins

验证后按对齐

<form class="form-inline form-padding">
        <div class="form-group">
            <div class="input-group">
                <input class="form-control" placeholder="First Name" name="firstname" type="text" />
            </div>
        </div>

        <div class="form-group">
            <div class="input-group">
                <input class="form-control" placeholder="Last Name" name="lastname" type="text" />
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <button type="submit" id="form-button" class="btn btn-primary">Load</button>
            </div>
        </div>
    </form>

验证码:

$('form').validate({
        rules: {
            firstname: {
                minlength: 3,
                maxlength: 15,
                required: true
            },
            lastname: {
                minlength: 3,
                maxlength: 15,
                required: true
            }
        },
        highlight: function(element) {
            $(element).closest('.form-group').addClass('has-error');
        },
        unhighlight: function(element) {
            $(element).closest('.form-group').removeClass('has-error');
        },
        errorElement: 'span',
        errorClass: 'help-block',
        errorPlacement: function(error, element) {
            if(element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }
    });

表单效果很好,但是当我点击“加载”按钮时,按钮的对齐方式不正确。我无法创造一个小提琴,我已经附上相同的屏幕截图。

在提交表格之前 Before Form Submition

表格提交后 enter image description here

验证后按对齐

1 个答案:

答案 0 :(得分:14)

添加此CSS会再次正确对齐表单:

.form-inline > .form-group {
    vertical-align: top;
}

http://jsfiddle.net/Au33X/