Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular material mat-select drop-down width

The current drop-down box has width greater than the the width of the line:
enter image description here

Is there a way to get rid of the extra width?
enter image description here

Here is my current code:

html:

<mat-form-field>
    <mat-select disableOptionCentering placeholder="Choose an option">
      <mat-option [value]="option" *ngFor="let option of my_list">
          {{ option }}
      </mat-option>
    </mat-select>
</mat-form-field>


my_list:

export const my_list: string[] = [ "a", "b", "c", "d"];


style.css:

.mat-select-panel{
    margin-left: 15px;
    margin-top: 28px;
}
like image 628
Meng Avatar asked Sep 18 '18 13:09

Meng


2 Answers

For anyone still trying to figure out without making the actual select smaller or wider.

The mat-select-panel uses 100% of the mat-select width plus 32px

min-width: calc(100% + 32px)

You can override this styling with ng-deep:

::ng-deep .mat-select-panel {
    min-width: 100% !important;
}
like image 55
RDNotorious Avatar answered Oct 02 '22 15:10

RDNotorious


Try this and change width:

   <mat-select style="width:10px">
like image 25
rikg93 Avatar answered Oct 02 '22 14:10

rikg93