wie kann ich den Inhalt der 2-Komponenten-Karte für das Kartenmaterial als scrollfähig machen? Ich habe auf der Material 2-Website nichts gefunden
Dies ist keine integrierte Funktion. Um den Inhalt scrollbar zu machen, legen Sie eine Höhe für den <mat-card-content>
-Selektor fest. Hier ist ein Beispiel:
<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>
Link zu StackBlitz Demo .
Sie können Flexbox dafür einsetzen:
Fügen Sie eine Klasse scrollable-content
zu Ihrem mat-card
hinzu, damit der Inhalt die Karte ausfüllt.
.mat-card.scrollable-content {
overflow: hidden;
display: flex;
flex-direction: column;
> .mat-card-title-group {
display: block;
}
> .mat-card-content {
overflow-y: auto;
}
}
Versuche dies. Der entscheidende Punkt ist die Einstellung der Position: absolut im scrollbaren Div:
.flex {
flex: 1 1 auto;
}
.scrollable {
overflow: auto;
box-sizing: border-box;
position: absolute;
right: 0;
top: 0;
width: 100%;
height: 100%;
}
<mat-card class="flex">
<div class="scrollable">
...
</div>
</mat-card>
Hier ist, was ich in meinem eigenen Code getan habe.
Sie können einen ähnlichen Ansatz verfolgen, aber es funktioniert.
.css
:Host {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
.content {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
align-content: center;
}
.policy-card {
width: 80%;
min-width: 280px;
height: 70%;
min-height: 280px;
margin: auto;
font-weight: unset !important;
box-shadow: 0px 3px 15px 0px rgba(0, 0, 0, 0.35);
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
align-content: center;
}
.header-image {
background-color: #44c2cc;
}
.text-container {
overflow-y: scroll;
}
.html
<mat-sidenav-container class="container">
<mat-sidenav-content class="content">
<mat-card class="policy-card">
<mat-card-header>
<div mat-card-avatar class="header-image"></div>
<mat-card-title>Title</mat-card-title>
<mat-card-subtitle>Subtitle</mat-card-subtitle>
</mat-card-header>
<mat-card-actions>
<button mat-button>LIKE</button>
<button mat-button>SHARE</button>
</mat-card-actions>
<mat-card-content [style.overflow]="'auto'">
<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>