【发布时间】:2021-03-27 09:06:24
【问题描述】:
是否可以根据是否使用网格区域来设置css网格行高?
.container {
height: 100vh;
grid-template-areas:
"mobile-head mobile-head mobile-head"
"nav app app"
"footer footer footer";
}
.nav {
grid-area: nav
}
<div class="container">
<div class="nav">Nav stuff</div>
</div>
鉴于上面的网格模板和 html,我在导航区域看到了导航的东西,但移动导航区域自然占据了屏幕高度的 1/3。因为没有具有 grid-area: mobile-head 的 div 我希望高度为 0px。
但如果我将 .nav 更改为
...
.nav {
grid-area: mobile-head
}
我希望该行的高度固定为 200 像素。
我可以靠近。当移动区域中没有任何内容时,我可以让行的高度为 0:
...
grid-template-rows: minmax(0px, auto) 1fr 1fr
但是高度是由内容决定的,而不是网格。
我相当确定实现我想要做的唯一选择是使用 2 个网格和媒体查询。 (我想将导航放在桌面的左侧,如果是移动设备,则放在顶部)
【问题讨论】:
-
您的网格区域声明中没有定义
mobile-nav区域。你的意思是mobile-head?