Yh1234
Yh1234

Reputation: 151

Angular Material form field appearance padding size

On

<mat-form-field appearance="outline">

Is it possible to reduce the default padding size of the border?

In the developer tool I can find the class and able to reduce size.

enter image description here

Putting this class in my css would not change the size.

Not sure how to put class name in my css to change the padding.

Upvotes: 2

Views: 10964

Answers (5)

kff
kff

Reputation: 51

Try adding this class from styles.css

div.mat-form-field-infix {
  padding: 0em 0 !important
}

Upvotes: 5

Vanley
Vanley

Reputation: 131

Rather get rid of placeholder for mat-label itself when it's not present by adding this to your root.css

.mat-form-field.mat-form-field-appearance-outline:not(.mat-form-field-has-label){
  .mat-form-field-infix {
    border-top: 0 !important;
  }
}

Upvotes: 0

jmuhire
jmuhire

Reputation: 2221

To reduce the field padding I had to override the appearance-outline and the infix classes like this :

::ng-deep .mat-form-field-appearance-outline .mat-form-field-infix {
  padding: 0.7em 0 0.7em 0 !important;
  top: -0.25em;
}

Upvotes: 6

Kostas Valais
Kostas Valais

Reputation: 165

Try ng-deep in your component's scss

::ng-deep  .mat-form-field-infix {
  padding: 0em 0;
}

https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep

Upvotes: 4

Vinod Kumar Kashyap
Vinod Kumar Kashyap

Reputation: 103

You can try padding: 0em 0 !important

Upvotes: 0

Related Questions