我不明白 flex-grow 属性吗? [英] Do I not understand the flex-grow property?
本文介绍了我不明白 flex-grow 属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
恐怕我一定不了解 flex-grow.如果你跳到下面的 JSFiddle - 按照我的理解,.big
应该是另一个 .flex-item
大小的三倍.如您所见,并非如此.为什么?
I'm afraid I must not understand flex-grow. If you jump to the JSFiddle below - the way I understand it, .big
should be three times the size of the other .flex-item
. As you can see, not so. Why?
.flex-container {
display:flex;
padding:0 20%;
}
.flex-item {
flex-grow:1;
list-style-type:none;
border:1px solid black;
}
.big {
flex-grow:3;
}
<ul class="flex-container">
<li class="flex-item big">Why isn't this exactly three times the size of the other one?</li>
<li class="flex-item">Not really working like expected I don't think...</li>
</ul>
推荐答案
您还必须为 flex-basis
指定一个值(不指定此属性会导致与使用初始值类似的行为,自动).
You have to specify a value for flex-basis
as well (not specifying this property causes behaviour similar to using the initial value, auto).
向两个孩子添加 flex-basis: 0;
或仅使用 简写:
Add flex-basis: 0;
to both children or just set it with the shorthand:
.flex-item {
flex: 1; /* flex-basis is 0 if omitted */
}
.big {
flex-grow: 3;
}
http://codepen.io/anon/pen/JEcBa
这篇关于我不明白 flex-grow 属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文