【发布时间】:2018-01-29 15:39:24
【问题描述】:
我有一张使用 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>
【问题讨论】:
-
不是按原样回答问题,但可能仍然有价值:我会用 flexbox 和
.two和.three周围的额外容器来做这件事:jsfiddle.net/9nxpvs5m/2跨度>