flexbox 和 wrap 属性 [英] flexbox and wrap property
问题描述
我正在使用 phonegap 开发和应用程序.我想使用 flexbox 在我的主要应用程序区域中布局一些按钮.
有人可以解释为什么这个 http://jsfiddle.net/apYLB/ 没有将元素包裹在最新的铬?
HTML:
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div><div class="flex-item">5</div><div class="flex-item">6</div>
CSS:
.flex-container {显示:-webkit-box;显示:弹性;flex-wrap: 包裹;-webkit-flex-wrap:包裹;-ms-flex-wrap:包裹;-webkit-flex-direction: 行;-webkit-flex-flow:行换行;flex-flow:行包装;-webkit-box-align: 结束;-moz-box-align:结束;框对齐:结束;-webkit-box-pack: 中心;-moz-box-pack:中心;盒装:中心;justify-content:space-around;高度:100%;}.flex-item {边距:0 10px 25px 0;宽度:86px;边框:1px 实心 #000;}.flex-item img {最大高度:80px;}
它们是水平放置的,只出现了 3 个半盒子.
这里有很多地方不太对劲.首先,您将旧属性与新属性混合在一起(display: -webkit-box
来自 2009 草案,但 -webkit-flex-flow
来自标准草案).
其次,2009 年的 Flexbox 实现都不支持 box-lines: multiple
,这是启用包装所必需的.遗憾的是,几乎所有的移动设备都只支持 2009 年的草案.支持现代规范的 Firefox 版本目前也不支持包装(flex-flow 和 flex-wrap 是支持的属性,但不支持与包装相关的值).
第三,您有 justify-content: space-around
,但它的 2009 版本设置为 box-pack: center
.中心是所有草稿的中心.
http://cssdeck.com/labs/ccamtvl5
.flex-container {显示:-ms-flexbox;显示:-webkit-flex;-webkit-flex-wrap:包裹;-ms-flex-wrap:包裹;flex-wrap: 包裹;-ms-flex-line-pack: 结束;-webkit-align-content: flex-end;对齐内容:flex-end;-ms-flex-pack:分发;-webkit-justify-content:空间环绕;justify-content:空间环绕;高度:100%;}@supports (flex-wrap: wrap) {/* 从不完整的 Firefox 版本中隐藏 */.flex 容器 {显示:弹性;}}
更新:自版本 28 起,包装现在可在 Firefox 中使用,但仅在使用现代属性时(不是旧的前缀属性,如 display: -moz-box
).
I am developing and app with phonegap. I wanted to use the flexbox to layout some buttons in my main application area.
Can somebody explain why this http://jsfiddle.net/apYLB/ doesn't wrap elements in latest chrome?
HTML:
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
<div class="flex-item">6</div>
</div>
CSS:
.flex-container {
display: -webkit-box;
display: flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
-webkit-flex-direction: row;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-box-align: end;
-moz-box-align: end;
box-align: end;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
justify-content:space-around;
height:100%;
}
.flex-item {
margin:0 10px 25px 0;
width:86px;
border:1px solid #000;
}
.flex-item img {
max-height:80px;
}
They are laid horizzontally and only 3 and a half boxes appear.
You have quite a few things not quite right here. First, you're mixing old properties with new properties (display: -webkit-box
is from the 2009 draft, but -webkit-flex-flow
is from the standard draft).
Second, none of the 2009 Flexbox implementations support box-lines: multiple
, which is required for enabling wrapping. Sadly, nearly all mobile devices support only the 2009 draft. Firefox versions that support the modern specification currently do not support wrapping either (flex-flow and flex-wrap are supported properties, but the values pertaining to wrapping are not supported).
Third, you've got justify-content: space-around
, but its 2009 counterpart is set to box-pack: center
. Center is center in all drafts.
http://cssdeck.com/labs/ccamtvl5
.flex-container {
display: -ms-flexbox;
display: -webkit-flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-ms-flex-line-pack: end;
-webkit-align-content: flex-end;
align-content: flex-end;
-ms-flex-pack: distribute;
-webkit-justify-content: space-around;
justify-content: space-around;
height: 100%;
}
@supports (flex-wrap: wrap) { /* hide from incomplete Firefox versions */
.flex-container {
display: flex;
}
}
Update: Wrapping now works in Firefox as of version 28, but only when using the modern properties (not the old prefixed ones like display: -moz-box
).
这篇关于flexbox 和 wrap 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!