Вместо этого:
grid-template-rows: min-content auto
Попробуйте:
grid-template-rows: min-content 1fr
С 1fr
вы говорите второму ряду использовать все свободное пространство, доступное в столбце,Следовательно, когда в элементе .first
нет содержимого, элемент .second
занимает пробел.
Проблема с auto
состоит в том, что его длина равна относительно других элементов сетки наотслеживать .Это означает, что он не всегда будет сжиматься, чтобы соответствовать одному конкретному элементу (как, например, min-content
), и не позволит элементу полностью исчезнуть, если другой элемент имеет некоторый размер (как вы видите вваш код).
.grid {
display: grid;
grid-template-rows: min-content 1fr; /* adjustment */
grid-template-columns: 60% 40%;
grid-template-areas:
"main first"
"main last";
}
.first { grid-area: first; background-color: orange; }
.main { grid-area: main; background-color: aqua; }
.last { grid-area: last; background-color: lightgray; }
<div class="grid">
<b class="first">Grant me revenge!</b>
<b class="main">Arnold ipsum. Just bodies. I need your clothes, your boots, and your motorcycle. Grant me revenge! And if you do not listen, then to HELL with you. Make it quick because my horse is getting tired. Come on don't bullshit me. Into the tunnel. Bring your toy back to the carpet.</b>
<b class="last">Make it quick because my horse is getting tired.</b>
</div>
<br>
<div class="grid">
<b class="first"></b>
<b class="main">Arnold ipsum. Just bodies. I need your clothes, your boots, and your motorcycle. Grant me revenge! And if you do not listen, then to HELL with you. Make it quick because my horse is getting tired. Come on don't bullshit me. Into the tunnel. Bring your toy back to the carpet.</b>
<b class="last">Make it quick because my horse is getting tired.</b>
</div>