角度可滚动垫选择列表?

mic*_*cer 8 html angular-material angular-material2 angular

我有个问题。我没有在堆栈上找到任何熟悉的问题,所以我在这里问,是否可以<mat-selection-list>滚动(Angular 7)?当项目太多而无法容纳一个窗口时,我想在右侧显示滚动条。

<mat-card fxFlex="33%">
<mat-selection-list>
  <mat-list-item
    *ngFor="let product of products"
    [class.selected]="product === selectedproduct"
    (click)="onSelect(product)"
  >
  </mat-list-item>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)

Oen*_*n44 13

简单的 CSS

mat-selection-list {
  max-height: 400px;
  overflow: auto;
}
Run Code Online (Sandbox Code Playgroud)

StackBlitz 演示


Pra*_*ale 6

通过设置自定义 CSS 属性?

花式滚动条的 CSS 仅支持 Chrome 浏览器:

.custom-scroll-bar{
    height:70vh;
    overflow-y:scroll;
    overflow-x: hidden;
}

.custom-scroll-bar::-webkit-scrollbar{
    width: 5px;
}

.custom-scroll-bar::-webkit-scrollbar-thumb{
    background: rgba(0,0,0,.26);
}
Run Code Online (Sandbox Code Playgroud)

对于 Firefox 和 Internet Explorer,只需简单地使用:

.custom-scroll-bar{
    height:70vh;
    overflow-y:scroll;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<mat-selection-list #shoes class="custom-scroll-bar">
  <mat-list-option *ngFor="let shoe of typesOfShoes">
    {{shoe}}
  </mat-list-option>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)

StackBlitz Example