mat-list-item
is by default using the full width of its container and setting each item as display: block
. To overrule this, you need to override the default Angular (Material) styling that comes with <mat-list>
.
Setting .mat-list-test
to display: flex
and adding flex-flow: row wrap
will make it go to the next line when there's not enough space available. Next to that, as said, the .mat-list-item
styling is taking the full width. You can override it by setting display: initial
and width: auto
. Read more about flexbox at MDN.
CSS
.mat-list-test {
display: flex;
flex-flow: row wrap;
}
.mat-list-base .mat-list-item.mat-list-item-test {
display: initial;
width: auto;
}
See this example on StackBlitz to show the outcome.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…