浮动标签和占位符重叠 [英] floating label and placeholder overlapping

查看:79
本文介绍了浮动标签和占位符重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="form-group form-default form-spacing">
     <input class="form-control" placeholder="Name" type="text" required>
     <span class="form-bar"></span>
     <label class="float-label">Name</label>
</div>

这是CSS,

.form-material {
    .form-group {
        position: relative;

        &.form-static-label .form-control {
            ~.float-label {
                top: -14px;
            }
        }
    }

    .form-control {

        &:focus {
            border-color: transparent;
            outline: none;
            box-shadow: none;

        }

        &:focus,
        &:valid {
            ~.float-label {
                top: -14px;
            }
        }
    }

如果我专注于文本字段,则效果很好. 但是当没有焦点时,它就会重叠. asdasd dasd dasdsad广告asd das dasd asd a das

if i focus on text field it works fine. but when there is no focus it's overlapping. asdasd dasd dasdsad ad asd das dasd asd a das

推荐答案

请尝试以下操作:

npm install-保存@ angular/material @ angular/cdk @ angular/animations

npm install --save @angular/material @angular/cdk @angular/animations

在app.module.ts中:

import {MatFormFieldModule} from '@angular/material/form-field';

html:

<form [formGroup]="addressForm" novalidate (ngSubmit)="onSubmit()">
  <mat-card class="shipping-card">
    <mat-card-header>
      <mat-card-title>Address, Neighborhood or ZIP</mat-card-title>
    </mat-card-header>
    <mat-card-content>

      <div *ngIf="hasUnitNumber">
        <div class="col">
          <mat-form-field class="full-width">
            <textarea matInput placeholder="first Name" formControlName="firstName"></textarea>
          </mat-form-field>
        </div>
      </div>

    </mat-card-content>
    <mat-card-actions>
      <button mat-raised-button color="primary" type="submit">Submit</button>
    </mat-card-actions>
  </mat-card>
</form>

CSS:

.full-width {
  width: 100%;
}

.shipping-card {
  min-width: 120px;
  max-width: 620px;
  margin: 20px auto;
}

.mat-radio-button {
  display: block;
  margin: 5px 0;
}

.row {
  display: flex;
  flex-direction: row;
}

.col {
  flex: 1;
  margin-right: 20px;
}

.col:last-child {
  margin-right: 0;
}

打字稿组件:

export class MyFormComponent {

addressForm = this.fb.group({
    firstName: [null, Validators.required],
  });

hasUnitNumber = false;

constructor(private fb: FormBuilder) {}

  onSubmit() {
    alert('Thanks!');
  }
}

这篇关于浮动标签和占位符重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆