角滚动的垫选择列表?

时间:2018-12-31 12:39:47

标签: angular angular-material angular-material2

我有一个问题。我没有在堆栈上找到任何熟悉的问题,所以我在这里问,是否可以使<mat-selection-list>滚动(角度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>

3 个答案:

答案 0 :(得分:1)

您可以尝试:

<mat-card fxFlex="33%">
     <mat-selection-list [style.overflow]="'auto'" [style.height.px]="'300'">
         <mat-list-item
              *ngFor="let product of products"
              [class.selected]="product === selectedproduct"
              (click)="onSelect(product)"> 
     </mat-list-item>
</mat-selection-list>

答案 1 :(得分:1)

通过设置自定义CSS属性?

仅用于Chrome浏览器的精美滚动条的CSS:

.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);
}

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

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

HTML:

<mat-selection-list #shoes class="custom-scroll-bar">
  <mat-list-option *ngFor="let shoe of typesOfShoes">
    {{shoe}}
  </mat-list-option>
</mat-selection-list>

StackBlitz Example

答案 2 :(得分:1)

简单的CSS

mat-selection-list {
  max-height: 400px;
  overflow: auto;
}

StackBlitz Demo