角度材料2卡可滚动

ank*_*tra 7 angular-material angular-material2 angular

如何使mat-card材料2组件内的内容滚动?我没有在材料2网站上找到任何东西

Fai*_*sal 8

这不是内置功能.要使内容可滚动,请为<mat-card-content>选择器设置高度.这是一个例子:

<mat-card>
    <mat-card-header>
        <mat-card-title>CARD TITLE</mat-card-title>
    </mat-card-header>
    <mat-card-content [style.overflow]="'auto'" [style.height.px]="'300'">
        <p>
            The Shiba Inu is the smallest of the six original and distinct
            spitz breeds of dog from Japan. A small, agile dog that copes very
            well with mountainous terrain, the Shiba Inu was originally bred
            for hunting.
        </p>
    </mat-card-content>
    <mat-card-actions>
        <button mat-button>LIKE</button>
        <button mat-button>SHARE</button>
    </mat-card-actions>
</mat-card>
Run Code Online (Sandbox Code Playgroud)

链接到StackBlitz演示.

  • 但如果我不想固定高度。它应该是有反应的。例如,如果我的文本非常少,那么高度仍然固定为 300。 (2认同)

j2L*_*L4e 5

您可以利用Flexbox实现以下目的:

scrollable-content在您的课程中添加一个课程,mat-card以使内容充实。

.mat-card.scrollable-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;

  > .mat-card-title-group {
    display: block;
  }

  > .mat-card-content {
    overflow-y: auto;
  }
}
Run Code Online (Sandbox Code Playgroud)
.mat-card.scrollable-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;

  > .mat-card-title-group {
    display: block;
  }

  > .mat-card-content {
    overflow-y: auto;
  }
}
Run Code Online (Sandbox Code Playgroud)