In general it might help to remember this:
1: A track is not a container.
2: A grid area is not a container.
3: A nested element is not a container unless you declare it as such.
Declarations such as max-width: 100%, object-fit: contain and so on describe how the element (e.g img) will behave inside its container - not inside the track or area it happens to have been placed in. And not inside the tag it lives in, nested inside its container. e.g after
HTML:
<div class="myContainer">
<div class="myTopRow">
<img src="myPic.jpg">
</div>
<div class="myBottomRow">
<span class="mySubText">Your subtext here.</span>
</div>
</div>
CSS:
.myContainer {
display: grid;
grid-template-rows: [row1Start] 1fr [row1End row2Start] 1fr [row2End];
grid-template-columns: [col1Start] 1fr [col1End];
}
.myTopRow {
grid-rows: row1Start / row1End;
grid-columns: col1Start / col1End;
}
.myBottomRow {
grid-rows: row2Start / row2End;
grid-columns: col1Start / col2End;
}
.myTopRow img {
max-width: 100%;
max-height: 100%;
object-fit: cover;
}
you've made a grid consisting of one column and two rows. The image in the top row will seem to spill over into the second row, colliding with that row's spanned text. In reality there's no overflow - the image is not contained by the top row (which has not been declared as a container, but is "merely" an area spanning tracks). Within it's actual container (the whole two-row box) the image is perfectly contained.