This means that if you have a set of flex items that are too wide for their container, they will overflow it. If you want to cause them to wrap once they become too wide you must add the flex-wrap property with a value of wrap , or use the shorthand flex-flow with values of row wrap or column wrap .
default flex-shrink: 1; If there's not enough space available in the container's main axis, the element will shrink by a factor of 1, and will wrap its content. flex-shrink: 0; The element will not shrink: it will retain the width it needs, and not wrap its content.
.container {
display: -webkit-flex;
}
.container>div:first-child{
white-space:nowrap;
-webkit-order:1;
-webkit-flex: 0 1 auto; /*important*/
text-overflow: ellipsis;
overflow:hidden;
min-width:0; /* new algorithm overrides the width calculation */
}
.container > div:last-child {
-webkit-flex: 1;
-webkit-order:2;
background: red;
-webkit-flex:1 0 auto; /*important*/
}
.container > div:first-child:hover{
white-space:normal;
}
<div class="container">
<div>foo barfoo bar</div>
<div>foo bar</div>
</div>
<div class="container">
<div>foo barfoo barfoo barfoo barfoo barfoo barfoo bar
foo barfoo barfoo barfoo barfoo barfoo barfoo bar
foo barfoo barfoo barfoo barfoo barfoo barfoo bar</div>
<div>foo bar</div>
</div>
<div class="container">
<div>foo barfoo bar</div>
<div>foo bar</div>
</div>
<div class="container">
<div>foo barfoo barfoo barfoo barfoo barfoo barfoo bar
foo barfoo barfoo barfoo barfoo barfoo barfoo bar
foo barfoo barfoo barfoo barfoo barfoo barfoo bar</div>
<div>foo bar</div>
</div><div class="container">
<div>foo barfoo bar</div>
<div>foo bar</div>
</div>
W3C specification says, "By default, flex items won't shrink below their minimum content size (the length of the longest word or fixed-size element). To change this, set the ‘min-width’ or ‘min-height’ property."
If we follow this line of reasoning, I believe the bug has been removed from Canary, not the other way round.
Check as soon as I put min-width
to 0
, it works in Canary.
So bug was in older implementations, and canary removes that bug.
This example is working in canary. http://jsfiddle.net/iamanubhavsaini/zWtBu/
I used Google Chrome Version 23.0.1245.0 canary.
You can set the preferred size of the child by setting the third value of the flex
property to auto, like so:
flex: 1 0 auto;
This is shorthand for setting the flex-basis
property.
(Example)
As noted in the comments however, this doesn't seem to work in Chrome Canary, although I'm not sure why.
Update: This is not the answer. It solves different problem, and it was a step in finding the real answer. So I am keeping it for the historical reasons. Please don't vote on it.
I believe this is your answer: http://jsfiddle.net/iamanubhavsaini/zWtBu/2/
refer W3C
for the first element
-webkit-flex: 0 1 auto; /* important to note */
and for the second element
-webkit-flex:1 0 auto; /* important to note */
are the properties and values that do the trick.
Read more at http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/#flex
and this is how you reverse the order: http://jsfiddle.net/iamanubhavsaini/zWtBu/3/
and this one with the predefined minimum width of the red-backgrounded-thingy: http://jsfiddle.net/iamanubhavsaini/zWtBu/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With