Sea*_*ean 32 html css html5 flexbox
是否可以使flex元素忽略子元素,因此它的大小不会影响其他元素?
例如,我有一个包装器display: flex.它有标题,内容和页脚.
<div class="wrapper">
<header></header>
<article></article>
<footer></footer>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望包装器忽略标头标签(标头将固定在窗口的顶部).该文章将设置为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;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将标题移到包装器之外但是我有很多现有的代码会让它变得更加困难.我甚至可能要问什么?
小智 41
在你的.wrapper声明中flex-wrap: wrap.然后,对于标题,您可以添加样式flex-basis: 100%,这将强制标题下方的所有其他内容.