I need this label stop from floating. I need it to be still. The input is from Angular Material. https://material.angular.io/components/form-field/examples
The code is the following one:
Phone
If someone can help me, I'am a rookie in programming. Thanks in advance.
I tried putting classes in CSS but none of them worked.
.mat-form-field-appearance-outline .mat-form-field-label {
transform: translateY(-50%);
}
.mat-mdc-floating-label.mat-mdc-form-field {
transform: none !important;
}
.mat-mdc-form-field .mat-mdc-floating-label.mat-mdc-form-field {
transform: none !important;
}
.mat-mdc-form-field.ng-touched .mat-mdc-floating-label.mat-mdc-form-field {
transform: none !important;
}
.mat-mdc-form-field.ng-touched .mat-mdc-floating-label.mat-mdc-form-field[ng-reflect-floating="true"] {
transform: none !important;
}
.mat-form-field.mat-focused .mat-form-field-label {
transform: none !important;
}
You can use the floatLabel propertie like this:
The default value is auto in a form-field, so use always to stop floating behaviour.
And to avoid duplicate floatLabel properties in your template, angular material provides MAT_FORM_FIELD_DEFAULT_OPTIONS providers that you can inject in your component like:
Template: