[英]flex-basis not working as expected
As i understand flex-basis is responsible for deciding the size of an element.据我了解,flex-basis 负责决定元素的大小。
In the example below, I am trying to size all boxes equally to 100px.在下面的示例中,我尝试将所有框的大小均等为 100 像素。 Just using flex-basis is not achieving the effect.仅使用 flex-basis 并不能达到效果。
.each_box {
-webkit-flex-grow: 0;
-webkit-flex-shrink: 0;
-webkit-flex-basis: 100px;
flex-grow: 0;
flex-shrink: 0;
flex-basis: 100px;
background-color: yellow;
height: 50px;
border: 1px solid black;
}
Plnkr here: http://plnkr.co/edit/LvrrzHWIw1tPGwK05bCU Plnkr在这里: http ://plnkr.co/edit/LvrrzHWIw1tPGwK05bCU
I found I had to use min-width as well as flex-basis in Chrome.我发现我必须在 Chrome 中使用 min-width 和 flex-basis 。 I'm not sure if I had another problem that caused this.我不确定是否还有其他问题导致了这种情况。
.flex-container {
display: flex;
width: 100%;
}
.flex-child {
flex-basis: 50%;
min-width: 50%;
}
The flex-grow
, flex-shrink
, flex-basis
properties only have an effect on elements in a flex container -- ie elements whose parent has display:flex
. flex-grow
、 flex-shrink
、 flex-basis
属性只对flex 容器中的元素有影响——即父元素具有display:flex
元素。
You need to put your each_box
divs directly inside of a display:flex
element for them to honor their flex-related properties.您需要将each_box
div 直接放在display:flex
元素中,以便它们尊重与 flex 相关的属性。
Specifically, your markup looks like this (from right clicking one of the yellow divs + hitting "inspect" in Firefox):具体来说,您的标记如下所示(右键单击黄色 div 之一 + 在 Firefox 中点击“检查”):
<div class="container">
<!-- ngRepeat: stock in stockList -->
<div class="ng-scope" ng-repeat="stock in stockList">
<div class="each_box ng-binding">
0-FB/100
You've got container
styled as display:flex
, but that does no good for your each_box
elements, because they're grandchildren, separated from the flex container by the display:block
ng-scope.您的container
样式为display:flex
,但这对您的each_box
元素没有好处,因为它们是孙子元素,通过display:block
ng-scope 与 flex 容器分开。
So you either need to get rid of the ng-scope
wrapper, or make it also have display:flex
.所以你要么需要摆脱ng-scope
包装器,要么让它也有display:flex
。
Add a width: width:100px;
添加宽度: width:100px;
flex-basis
gives a default proportion, which will then grow or shrink. flex-basis
给出了一个默认的比例,然后它会增长或缩小。
Be sure to also add: flex-wrap: wrap;
一定还要加上: flex-wrap: wrap;
because the default value nowrap
in order to fit everything in one line can affect the size of the elements (eg: width, flex-basis, etc..).因为默认值nowrap
为了将所有内容都放在一行中会影响元素的大小(例如:宽度、flex-basis 等)。
All works for me:一切都对我有用:
.flex-child { width:0; }
AND和
.flex-child { min-width:0; }
AND和
.flex-child { flex-shrink:0; } /* no scrollbars inside */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.