我有一张用 CSS 网格布局构建的卡片。左边可能有一个图像,右上角可能有一些文本,右下角可能有一个按钮或链接。
在下面的代码中,如何让绿色区域占用尽可能多的空间,同时让蓝色区域占用尽可能少的空间?
果岭应尽可能将蓝色区域向下推。
https://jsfiddle.net/9nxpvs5m/
.grid {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-areas:
"one two"
"one three"
}
.one {
background: red;
grid-area: one;
padding: 50px 0;
}
.two {
background: green;
grid-area: two;
}
.three {
background: blue;
grid-area: three;
}
<div class="grid">
<div class="one">
One
</div>
<div class="two">
Two
</div>
<div class="three">
Three
</div>
</div>
原文由 Jens Törnell 发布,翻译遵循 CC BY-SA 4.0 许可协议
将
grid-template-rows: 1fr min-content;
添加到您的.grid
将得到您所追求的 :)。Jens 编辑: 为了获得更好的浏览器支持,可以改用:
grid-template-rows: 1fr auto;
,至少在这种情况下是这样。