因此,我在移动设备上有一个简单的三个段落堆栈,我想在较大的视窗上的网格中设置样式,而不改变源顺序。
第一部分可能只有几行或者根本没有内容。
在这种情况下,如何使第一行折叠以便第二行填充空间?也就是说,当顶部为空时,最后一部分应该出现在顶部
.grid {
display: grid;
grid-template-rows: min-content auto;
grid-template-columns: 60% 40%;
grid-template-areas:
"main first"
"main last";
}
.first { grid-area: first; }
.main { grid-area: main; }
.last { grid-area: last; }
<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>
发布于 2018-06-06 06:17:04
而不是这样:
grid-template-rows: min-content auto
试试这个:
grid-template-rows: min-content 1fr
使用1fr
,您告诉第二行消耗该列中所有可用的空闲空间。因此,当.first
元素中没有内容时,.second
元素将占用空间。
auto
的问题是它的长度是relative to other grid items on the track。这意味着它不会总是收缩以适应特定的项目(就像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>
https://stackoverflow.com/questions/50708974
复制相似问题