I am learning CSS flexbox and doing a simple layout where I wanted the first flexible child to be displayed with the 100% width of the parent and remaining the flexible element wrapped below. In addition, wrapped flex items should occupy the width in a certain ratio (easy to set using the flex property).
To do this, I set the flex-basis property of the first flex element to 100% and set the flex property of the next 2 in the relation I want. Here's what the corresponding CSS looks like (link to the full script below):
.main{ max-width: 1000px; margin: 100px auto; display: flex; flex-flow: row wrap; } .flex-item:nth-child(1) { flex:1 100%; } .flex-item:nth-child(2) { flex:2; } .flex-item:nth-child(3) { flex:3; }
This should set the first element width to 1000px, and for the next two - 400px and 600px respectively; wrapped and displayed below the first child.
But for some reason CSS is interrupted, and the 2nd and 3rd positions are being forced out of the main container.
What is weirder is that adding a field to flex elements eliminates all this, and I donβt understand how this happens (I have to do something stupid). Even adding some border or padding to the ".flex-item" rule works.
.flex-item{ margin: 5px; }
Here is the JS Fiddle . You can try not to comment on the ".flex-item" rule in CSS to see what happens.
I was lazy not to add any prefixes (since almost every new browser supports it), but the problem is the same as in the latest FF, IE and chrome.
source share