I try to use the following structure to generate the layout described below.
<div class="flexbox">
<div class="box box1">child 1</div>
<div class="box box2">child 2</div>
<div class="box box3">child 3</div>
<div class="box box4">child 4</div>
</div>
I made an example for that here.
The layout should be as follows:
- if there is only one box inside the flexbox it should have 50% of the width inside the flexbox (see following figure)
- if there are two boxes they both should take 50% of the space inside the flexbox
- if there are three boxes, each box should take 50% of the space, while the first two boxes are in row 1 and the third box appears in row 2
How can I achieve this kind of layout with css?
Edit: The boxes might not have the same height. This means they should fill the remaining space vertically. The width is always the same. See the following image for an example.
Edit: I found a way to make masonry with pure css see here: http://jsfiddle.net/confile/aGXzU/
The problem is that the boxes are in the wrong order. They should be from left to right and from top to bottom like this:
1 2 3
4 5 6
7 8 9
Is there a way to get this with css and only little javascript?