To add custom styling to your component, you can include the following CSS/SCSS code in either the component's specific .scss
or .css
file, or in the main global .scss
or .css
file based on your requirements.
::ng-deep .mat-form-field-appearance-outline .mat-form-field-flex {
height: 40px !important
}
This snippet adjusts the top padding of the .mat-form-field-infix element to 1px and uses the !important flag to prioritize this style over conflicting ones.
It's worth noting that the ::ng-deep selector is used to apply these styles globally within the component's template. However, this technique is deprecated and should be replaced with more modern approaches for component-level styling.
If you also need to center the text input, consider adding the following to your styling:
.mat-input-element {
position: relative;
top: -0.3em; /* Adjust as needed for vertical centering of placeholder/input text. */
}
Check out the before screenshot below:
https://i.sstatic.net/V2lGQ.png
And here's how it looks after applying the customized css/scss styling:
https://i.sstatic.net/haUrP.png