I am trying to understand why specifying the same minmax
for grid-template-rows
fails to produce the same type of result it seems to produce for grid-template-columns
.
Here is the HTML. It's very simple:
<html>
<body>
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</body>
</html>
Here is the CSS:
.container > div {
border: 1px solid red;
}
.container {
display: grid;
grid-template-columns: repeat(3, minmax(200px, 400px));
grid-template-rows: repeat(3, minmax(200px, 400px));
}
Here is the code line on CodePen: https://codepen.io/user1831902/pen/KKNyJQr
You can see that when you expand/shrink the width of the browser, each column does indeed expand to 400px
width and shrink down to 200px
. However, the height each row remains at 400px
.
Why is this going on? (My guess is that the browser sees the height below the viewport as "available space". Is that the case? If it is, how do you constrain it so it doesn't and the specified minmax
range is actually respected.
I've tried restricting the .container
with max-height
, but that didn't do anything.