Despite my Googling, I've found few examples on how to implement multiple line flexboxes. None of the code I've gotten from examples has worked. I have three elements inside a flexbox and I want the first to be on top and the second and third to be on the bottom row.
<div class="flexbox"> <div id="element1">element 1</div> <div id="element2">element 2</div> <div id="element3">element 3</div> </div>
I've tried using these properties:
.flexbox { width: 300px; display: box; display: -webkit-box; display: -moz-box; box-lines: multiple; flex-wrap: wrap; } #element1 { width: 100%; }
and giving it a set width but it still won't wrap, even if the first element has a width of 100%. Am I missing certain vendor prefixes or is my syntax wrong?
For 3 items per row, add on the flex items: flex-basis: 33.333333% You can also use the flex 's shorthand like the following: flex: 0 0 33.333333% => which also means flex-basis: 33.333333% .
Inserting a line-breaking flex itemUsing an element to break to a new flex row comes with an interesting effect: we can skip specifying the width of any item in our flex layout and rely completely on the line breaks to define the flow of our grid.
The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.
The flex box spec has changed in the last few months and you are using the old syntax. The new spec I believe is only currently implemented only in Chrome Canary and to some extent in latest chrome. (It's a little buggy) box-lines multiple is gone so to achieve this vertical layout there are a few ways. Using -webkit-flex-direction:column; so
<div id="flexbox"> <div class="box">DIV 1</div> <div class="box">DIV 2</div> <div class="box">DIV 3</div> </div>
and css :
#flexbox { display: -webkit-flex; -webkit-flex-direction: column; width: 500px; height: auto; min-height: 200px; } #flexbox .box { -webkit-flex: 1; }
Using wrapping:
-webkit-flex-wrap: wrap;
and setting your direction to:
-webkit-flex-direction: row;
So
<div id="flexbox"> <div class="box">DIV 1</div> <div class="box">DIV 2</div> <div class="box">DIV 3</div> <div class="box">DIV 4</div> <div class="box bigger">DIV 5</div> <div class="box">DIV 6</div> </div> #flexbox { display: -webkit-flex; -webkit-flex-direction: row; -webkit-flex-wrap: wrap; width: 500px; height: auto; min-height: 200px; } #flexbox .box { -webkit-flex: 130px 1; } #flexbox .box.bigger { -webkit-flex: 330px 1; }
There's a whole bunch of examples on the spec page linked above.
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