【发布时间】:2021-09-20 15:03:41
【问题描述】:
我正在尝试在最新的 Chrome、Firefox 和 IE11 中实现这种布局:
我可以通过以下方式来解决这个问题:
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
html, body { height: 100%; padding: 0; margin: 0; }
p { line-height: 2em; }
header, footer, article { padding: 10px; }
#parent {
height: 100%;
display: flex;
flex-flow: column nowrap;
background-color: limegreen;
}
#parent > header {
flex: none;
background-color: limegreen;
}
#parent > footer {
flex: none;
}
#child {
display: flex;
flex-direction: column;
background-color: red;
height: 100%;
min-height: 0;
}
#child > header {
flex: none;
background-color: #aaa;
}
#child > article {
flex: 1 1 auto;
overflow-y: auto;
min-height: 0px;
}
#child > footer {
flex: none;
background-color: #aaa;
}
<section id="parent">
<header>Parent flex header </header>
<section id="child" >
<header>Child flex header</header>
<article>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
<p>Lots of content.</p>
</article>
<footer>Child flex footer</footer>
</section>
<footer>Parent flex footer</footer>
</section>
然而我觉得有些 CSS 有点奇怪,我想确保我有最大的机会不生成会在某些浏览器更新中中断的 CSS。这样做的原因是该软件将在实际硬件上运行(有点像您的路由器管理界面),并且不能像常规网站那样容易地更新。
所以困扰我的CSS是可滚动的article:
#child {
display: flex;
flex-direction: column;
background-color: red;
height: 100%;
min-height: 0;
}
我摆弄了height 和min-height 以使其在所有三个中都起作用。最初我只有height: 100%,但这在 Firefox 中不起作用。指定 min-height: 0 可以在 Chrome 和 FF 中工作,但不能在 IE 中工作。这个组合似乎满足了所有 3 个,但谁是正确的?我可以合理地确定这不会在下一个 FF 或 Chrome 中中断吗?从“规范角度”来看,这段代码有意义吗?
【问题讨论】: