I have a mat-grid-tile (parent) which contains a component app-window (child), which contains a mat-card at its root.
The app-window fills the mat-grid-tile as desired and is center-aligned both vertically and horizontally. Now I want the app-window's mat-card to do the same so that I can have a grid of equally spaced mat-cards.
How can I get the mat-card contained within app-window to fill the entire app-window? I have tried some ideas but none were successful; more details below.
StackBlitz example
Component HTML:
<mat-grid-list cols="3" rowHeight="4:3">
<mat-grid-tile>
<app-window></app-window>
</mat-grid-tile>
</mat-grid-list>
Component CSS:
app-window {
width: calc(100% - 10px);
height: calc(100% - 10px);
}
Attempted solutions and their results:
app-window's mat-card's width to a width and height of 100%. This makes the mat-card slightly larger than the mat-grid-tile that contains it. The desired behaviour would have been to match the size of the app-window.mat-card. As a result, the mat-card occupies the app-window's entire width but is only as tall as its content. I want it to always be the same height as the app-window.flex-grow: 1; to the mat-card. Based on my understanding, this should make the mat-card fill the entire space of the app-window, i.e. its parent container. However, there is no effect and the result is the same as the second solution's.On adding matRipple to a mat-card with mat-card-actions and clicking on the action button , the card size increases since the <mat-ripple-element> appears at the bottom and takes up some empty space.
<mat-card> is a content container for text, photos, and actions in the context of a single subject.
Hope you have figured this out by now but I'll provide this solution to others who might be seeing similar issues.
The reason height:100%; extends past the parent container is the mat-card box-sizing property is content-box by default. If you set it to border-box it will subtract the padding while determining the size to fill the parent.
The following should work for you:
app-window mat-card{
width: 100%;
height: 100%;
box-sizing: border-box;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With