gpt4 book ai didi

html - Bootstrap v.4.1 - 输入中断中的图标

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

我目前正在使用 Angular 6 和最新版本的 Bootstrap v4.1现在我尝试在输入表单中构建一个带有图标的 react 表单。由于在 Bootstrap 中并没有真正的方法将图标放在输入的左侧 - 我需要自己破解它。但这并不是真的有效。让我们仔细看看:

用例1

当没有错误 msg apper - 它看起来一切正常并且符合预期: enter image description here

用例2

但是当表单发生变化并且消息出现时 - 图标从表单中断开: enter image description here

代码

html:

<form [formGroup]="registerForm">
<div class="form-group required">
<label class="control-label">Email address:</label>
<input formControlName="username" type="email" class="form-control">
<span *ngIf="isFieldInvalid('username')" class="form-control-feedback-invalid-username"><fa class="danger" [name]="'ban'"></fa></span>
<span *ngIf="isFieldValid('username')" class="form-control-feedback-valid-username"><fa class="danger" [name]="'check'"></fa></span>

<span *ngIf="isFieldValidWithErrorType('username', 'required')" [ngClass]="displayFieldCss('username', 'required')">Username has to be set.</span>
<span *ngIf="isFieldValidWithErrorType('username', 'email')" [ngClass]="displayFieldCss('username', 'email')">Email should have right pattern.</span>
</div>

<div class="form-group required">
<label class="control-label">Password:</label>
<input formControlName="password" type="password" class="form-control">
<span *ngIf="isFieldInvalid('password')" class="form-control-feedback-invalid-password"><fa class="danger" [name]="'ban'"></fa></span>
<span *ngIf="isFieldValid('password')" class="form-control-feedback-valid-password"><fa class="danger" [name]="'check'"></fa></span>

<span *ngIf="isFieldValidWithErrorType('password', 'required')" [ngClass]="displayFieldCss('password', 'required')">Password has to be set.</span>

</div>
</form>

重要的类是form-control-feedback-username/password。它在 css 中看起来如下:

.form-control-feedback-invalid-username {
position: absolute;
z-index: 2;
right: 25px;
top: 77px;
color: red;
line-height: 34px;
pointer-events: none;
}

.form-control-feedback-valid-username {
position: absolute;
z-index: 2;
right: 25px;
top: 77px;
color: #35ef5f;
line-height: 34px;
pointer-events: none;
}

最佳答案

通过反复试验和@marco gomes 的建议,我弄清楚了图标如何保持一致:

.form-group {
position: relative;
.form-control-feedback-invalid-username {
position: absolute;
z-index: 2;
top: 40px;
right: 10px;
color: red;
pointer-events: none;
}

.form-control-feedback-valid-username {
position: absolute;
z-index: 2;
top: 40px;
right: 10px;
color: #35ef5f;
pointer-events: none;
}

.form-control-feedback-invalid-password {
position: absolute;
z-index: 2;
top: 40px;
right: 10px;
color: red;
pointer-events: none;
}

.form-control-feedback-valid-password {
position: absolute;
z-index: 2;
top: 40px;
right: 10px;
color: #35ef5f;
pointer-events: none;
}
}

关于html - Bootstrap v.4.1 - 输入中断中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51279882/

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