Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox stack different height childs [duplicate]

Tags:

I'm building an image portfolio site, and I need the images to stack depending on their variable size. This is what I have achieved with flexbox so far:

enter image description here

And this is where I'm trying to get!!

enter image description here

Does someone know how to make children stack this way on a flexbox display? I swear I can't find this particular structure anywhere on flexbox tutorials, though I've seen it several times on tumblr blog displays.

This is my code: http://jsfiddle.net/822h7ztd

.flexman {
    width:100%;
    padding: .2vw;
    flex-flow: row wrap;
    display: flex;
}
.flexman div {
    background: red;
    width: 100px;
    height:50px;
    margin: .2vw; 
}
like image 518
Andratwiro Avatar asked Nov 04 '15 02:11

Andratwiro


People also ask

How do I stop my flexbox from overlapping?

The best solution I've come up with is to set the services images to overflow: hidden and the staff images to nowrap, this prevents images from either gallery from overlapping with any other elements.

Can you set height of flexbox?

It can be changed by using the flex-direction property. To use flexbox, we have to set display: flex or inline-flex to flex-container. By default, the height and width of a flex-container are set to auto. But we can define a fixed amount to them.

How do you make flexbox children 100% height of their parents using CSS?

Getting the child of a flex-item to fill height 100% Set position: absolute; on the child. You can then set width/height as required (100% in my sample).


1 Answers

For anyone who might have encountered this, seems like what you are looking for is called a Masonry layout, which can be achieved with flexbox this way:

http://thenewcode.com/844/Easy-Masonry-Layout-With-Flexbox

like image 158
Andratwiro Avatar answered Oct 01 '22 06:10

Andratwiro