Reputation: 2204
I am using basic mat-select component in my project.
<mat-form-field>
<mat-select placeholder="Favorite food">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
how can i remove the underline,I have tried this answer too still no result.
Upvotes: 30
Views: 45544
Reputation: 2627
For legacy material components set appearance to none:
<mat-form-field appearance='none'>
For mdc components:
.mdc-line-ripple {
display: none;
}
Upvotes: 4
Reputation: 21
I had appearance="fill" on the mat-form-field. These settings worked to remove the underline for me:
scss:
.mat-form-field-appearance-fill {
.mat-form-field-underline {
display: none;
}
}
Add set encapsulation to ViewEncapsulation.None in the component:
encapsulation: ViewEncapsulation.None
Upvotes: 0
Reputation: 1727
Two options to solve the problem:
appearance="none"
in mat-form-field
tag <mat-form-field appearance="none">
.::ng-deep .mat-form-field-underline { display: none; }
Upvotes: 0
Reputation: 1177
If you want to hide underline in particular input only then you can do something like below.
<div class="select-block">
<mat-form-field>
<mat-select placeholder="Select Option">
<mat-option>One</mat-option>
<mat-option>Two</mat-option>
<mat-option>Three</mat-option>
</mat-select>
</mat-form-field>
</div>
.select-block{ /deep/ mat-form-field { &.mat-form-field-appearance-legacy { .mat-form-field-underline { display: none; } } } }
Try this way to hide the underline. Thanks.
Upvotes: 0
Reputation: 3016
::ng-deep
is going to be depracated.
Use css hierarchy. If you have a global css or scss file... then in the component, wrap this in a div and give it a class.
For example,
<div class="content-wrapper">
...all your html code here
</div>
Then, in your global css/scss file, you can target the .mat-form-field-underline
class like so:
.content-wrapper .mat-form-field-underline {
display: none;
}
Here, notice that we don't use comma after class names. This is using hierarchy. It saying that we only want to target the native .mat-form-field-underline
class that is wrapped inside the .content-wrapper
Hope this helps. Glad my senior developer had shared me this as we used ViewEncapsualtion, which bled css all over the place. This is the right solution to our use case, hope it helps yours.
This also works for other native mat classes for customization of your code/html.
Upvotes: 1
Reputation: 1348
You can also use the appearance
property on the <form-field>
. Setting appearance="none"
will remove the underline without any css hack. And you can also get rid of ::ng-deep
which is not recommended.
So your code will be like this.
<mat-form-field appearance="none">
<mat-select placeholder="Favorite food">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
For more information on appearance, you can check here. https://material.angular.io/components/form-field/overview#form-field-appearance-variants
Upvotes: 30
Reputation: 12813
You can do this:
::ng-deep .mat-form-field-underline {
display: none;
}
Upvotes: 69