【发布时间】:2019-05-16 01:48:49
【问题描述】:
据我所知,我的aside 元素和div.content 应该占用div.container 中可用空间的一半。此外,div.content 中的网格应占用所有可用的垂直空间。
问题是网格项目无法采用任何高度(如果没有硬编码)。此外,网格占用的所有垂直空间(因为grid-gap)都来自aside元素和div.content,这意味着div.content窃取aside的垂直空间,这两个元素不再相同的高度。
aside 的高度等于div.content 的高度减去网格的高度。
总之,flexbox为div.content设置的高度是禁止使用的。添加到 div.content 的子元素表现得更像它的兄弟元素。
* {
box-sizing: border-box;
}
body {
min-height: 100%;
margin: 0;
display: flex;
flex-direction: column;
}
html {
height: 100%;
}
header,
footer {
background-color: #1A1C22;
height: 100px;
}
.container {
flex: 1 0 400px;
display: flex;
flex-direction: column;
padding-top: 12px;
}
aside {
background-color: #6C757D;
flex: 1 1 auto;
}
.content {
flex: 1 1 auto;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: repeat(6, 1fr);
grid-gap: 20px;
border: 2px solid blue;
}
section {
background-color: #343A40;
border: 1px solid red;
}
<body>
<header></header>
<div class="container">
<aside></aside>
<div class="content">
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
</div>
</div>
<footer></footer>
</body>
【问题讨论】:
-
你应该考虑
flex:1 1 0%(the flex-basis:0%) and min-height:0 for content 但仍然是同样的问题 -
^ 以上似乎在 Firefox 上可以正常工作,但在 Chrome 上却不行