请帮助我了解灵活的盒子布局模型的一个问题,我在 Firefox 和 Chrome 中得到不同的结果。
考虑以下 HTML 片段:
<body>
<header>Header</header>
<footer>Footer</footer>
</body>
通过样式
body {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
}
header {
max-width: 400px;
height: 20px;
background-color: yellow;
margin: 0 auto;
}
footer {
width: 400px;
height: 20px;
background-color: green;
margin: 0 auto;
}
页眉框的最大宽度限制为 400 像素,而页脚的固定宽度为 400 像素。当我在基于 Gecko 的浏览器(在我的情况下为 Firefox 21 和 24)中尝试此代码时,页眉和页脚都是水平居中的(我希望通过给它们左右自动边距)但只有页脚的宽度为 400 像素,而即使有足够的水平空间可用,标题的宽度也只是内容的宽度。
在基于 WebKit/Blink 的浏览器(在我的例子中是 Chrome 25 和 28)中,页眉和页脚都居中并且都是 400px 宽(如果有足够的水平空间),这正是我想要实现的。
显然,Firefox 或 Chrome 一定是错误的。您如何理解规范:http ://www.w3.org/TR/css3-flexbox/ ://www.w3.org/TR/css3-flexbox/ ?期望的行为是什么?
如果你想玩,这里有一个 JSFiddle:http: //jsfiddle.net/4Rv7K/。
请注意,必须在 Firefox 的发布版本中启用灵活的盒子布局模型。它是设置 layout.css.flexbox.enabled。(没有它,实际上就不会测试任何关于 flexbox 的东西。)
PS:该错误在 Chromium 的引擎中,现在显然已修复:https ://code.google.com/p/chromium/issues/detail?id=242654