Horizontal masonry layout with flexbox CSS only
Here is one option using wrapped columns, but it requires a fixed height.
.card-container {
display: flex;
flex-flow: column wrap;
height:100vh;
align-items: center;
background-color: #888;
}
A better option for CSS masonry layout is to use columns, an example is on this blog post http://w3bits.com/css-masonry/
.masonry { /* Masonry container */
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
}
.item { /* Masonry bricks or child elements */
background-color: #eee;
display: inline-block;
margin: 0 0 1em;
width: 100%;
}
Create a Masonry grid with flexbox (or other CSS)
Try the new CSS Grid Layout:
grid-container { display: grid; /* 1 */ grid-auto-rows: 50px; /* 2 */ grid-gap: 10px; /* 3 */ grid-template-columns: repeat(auto-fill, minmax(30%, 1fr)); /* 4 */}
[short] { grid-row: span 1; /* 5 */ background-color: green;}
[tall] { grid-row: span 2; background-color: crimson;}
[taller] { grid-row: span 3; background-color: blue;}
[tallest] { grid-row: span 4; background-color: gray;}
<grid-container> <grid-item short></grid-item> <grid-item short></grid-item> <grid-item tall></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item> <grid-item taller></grid-item> <grid-item short></grid-item> <grid-item tallest></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item> <grid-item tallest></grid-item> <grid-item tall></grid-item> <grid-item taller></grid-item> <grid-item short></grid-item> <grid-item short></grid-item> <grid-item short></grid-item> <grid-item short></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item> <grid-item taller></grid-item> <grid-item short></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item> <grid-item short></grid-item> <grid-item tallest></grid-item> <grid-item taller></grid-item> <grid-item short></grid-item> <grid-item tallest></grid-item> <grid-item tall></grid-item> <grid-item short></grid-item></grid-container>
Related Topics
Two Divs, One Fixed Width, the Other, the Rest
Align Button at the Bottom of Div Using CSS
Run CSS3 Animation Only Once (At Page Loading)
CSS List Item Width/Height Does Not Work
How to Make an Inset Drop Shadow in Svg
Less CSS Set Variables in Media Query
Fit Div Size to Background Image
Custom Li List-Style with Font-Awesome Icon
The 'Justify-Content' Property Isn't Working
Two Divs the Same Line, One Dynamic Width, One Fixed
Webkit CSS to Control the Box Around the Color in an Input[Type=Color]
Where Do CSS and JavaScript Files Go in a Maven Web App Project
How to Remove Border from Specific Primefaces P:Panelgrid
Ie - Hidden Radio Button Not Checked When the Corresponding Label Is Clicked
CSS Focus Not Working in Safari and Chrome
Google Font Not Working on Safari
Assign CSS Attributes According to Class "Range"
How to Create a Sticky Footer That Plays Well with Bootstrap 3