gpt4 book ai didi

css - Bootstrap 图标与输入组对齐

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:20 24 4
gpt4 key购买 nike

我有 n 个这样的输入组:

<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input class="form-control" id="username" name="username" placeholder="Username" type="text">
</div>

这是它的样子:

username input group

这是一个 codepen .

我正在使用 jQuery 验证,它添加了一个带有错误消息的错误类,但这会拉伸(stretch)前置图标。

错误的html:

<div class="input-group has-error">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input class="form-control error" id="username" name="username" type="text">
<span class="help-block form-error">This user name is already registered.</span></div>

这就是它的样子:

User name with error

如何使图标保持相同的高度并内嵌错误消息?

最佳答案

您需要在input-group 之外追加错误信息

查看演示 HERE

试试这个:

JS:

$(document).ready(function(){
$('#registration-form').validate({
rules: {
name: {
required: true,
required: true
},

username: {
minlength: 6,
required: true
},
phone: {
minlength: 8,
required: true
},
password: {
required: true,
minlength: 6
},
confirm_password: {
required: true,
minlength: 6,
equalTo: "#password"
},

email: {
required: true,
email: true
},

address: {
minlength: 10,
required: true
},

agree: "required"

},
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);
}
},
success: function(label) {
label.addClass("valid").text("Ok!")
}

});
});

关于css - Bootstrap 图标与输入组对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40062971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com