【发布时间】:2015-10-11 14:16:48
【问题描述】:
我注意到 Firefox 和 Chrome 在以下 flexbox 布局中的一个有趣区别:
html,
body {
height: 100%;
min-height: 100%;
margin: 0px;
display: flex;
flex-direction: column;
}
header {
border: 1px solid #D3D3D3;
flex: 0 1 auto;
}
.row {
display: flex;
flex-direction: column;
flex: 1 0 auto;
flex-wrap: wrap;
}
.tab1 {
flex: 1 0 48%;
position: relative;
margin: 0.5em;
background-color: orange;
}
.tab2 {
flex: 1 0 48%;
position: relative;
margin: 0.5em;
background-color: blue;
}
.tab3 {
flex: 1 0 48%;
position: relative;
margin: 0.5em;
border: 1px solid lightgray;
background-color: green;
}
.tab4 {
flex: 1 0 48%;
position: relative;
margin: 0.5em;
border: 1px solid lightgray;
background-color: yellow;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<header>
</header>
<div class="row">
<div class="tab1"></div>
<div class="tab2"></div>
<div class="tab3"></div>
<div class="tab4"></div>
</div>
</body>
</html>
当我在 Chrome 43 中运行它时,我得到了水平矩形。但是,在 Firefox 39 中,这会产生垂直矩形。重要的部分是flex-direction: column; 和flex-wrap: wrap; 在类.row 的元素中的使用。
为了获得类似的布局,添加 height: 100%; 会在 Chrome 中提供垂直矩形。但是,由于(空)标题元素,这会在两个浏览器中创建一个滚动条。有谁知道这种布局差异的原因是什么以及修复它的最佳方法是什么?
更新:
顺便说一句,我有兴趣了解为什么 Chrome 和 Firefox 存在差异,而不是获得具有垂直矩形的布局。也许flex-direction: column 的使用有问题,或者我做错了什么。无论如何,知道这一点会很有帮助。
【问题讨论】:
-
对我的回答添加了更新
标签: css google-chrome firefox flexbox