How to center the mat-chips in a stacked mat-chip-list

6.8k views Asked by At

This is how the chips are stacked right now:

https://imgur.com/hf2J8Xa

The space on the left is clearly less then on the right. How can i center the chips so that the margins on both sides are even? I've tried using custom css classes with text-align: center and vertical-align:middle but none of that worked.

EDIT: For reference here is the code:

<mat-form-field  class = "chiplist" *ngIf="advancedFilterList.length > 0">
<mat-chip-list class="mat-chip-list-stacked" aria-orientation="vertical">
    <mat-chip *ngFor="let advancedFilter of advancedFilterList" [selectable]="selectable" 
        [removable]="removable" (removed)="remove(advancedFilter)" (click)="changeUnitSymbolAndPopulateFieldsWithSelectedFilterData(advancedFilter)">
        <mat-icon matChipRemove>cancel</mat-icon>  
        <div [innerHTML]="getFullFilterDescription(advancedFilter)"></div>
    </mat-chip>
  </mat-chip-list>
</mat-form-field>
1

There are 1 answers

3
JMF On

You should delete the class "mat-chip-list-stacked", since it has a width of 100%, so you would already see the mat-chip centered. If you want to add CSS, create your own class and add the corresponding styles

Example: mat-chip center