如何让 flex 元素忽略其子元素,使其大小不会影响其他元素?
比如说,我有一个包含标题、内容和页脚的容器,样式为 display: flex
。
<div class="wrapper">
<header></header>
<article></article>
<footer></footer>
</div>
我希望包装器忽略标题标签(标题将固定在窗口顶部)。文章将被设置为flex: 1
,以便占据其余空间,将页脚强制排在页面底部。以下是一些示例CSS:
.wrapper {
display: flex;
flex-direction: column;
height: 100%;
padding-top: 50px; /* Accounts for header */
}
header {
height: 50px;
position: fixed;
top: 0;
width: 100%;
}
article {
flex: 1;
}
footer {
height: 50px;
}
我知道我可以将标题移到包装器之外,但我有很多现有的代码,这会使问题变得更加困难。我所问的是否可能?
position: fixed
,所以我想知道这是否是问题的一部分。 - Sean