-1

I have a 3 column layout on my application where the items in the columns are all of equal width but varying height. I would like the items in the columns to take up all the available space per column. Image attached.

enter image description here

Any ideas on how to do this with CSS? Given a HTML layout like such:

<div className="container">
   <div className="item">
   <div className="item">
   <div className="item">
   <div className="item">
   <div className="item">
   <div className="item">
   ...
</div>

I was thinking of just working JSX in React to actually create 3 columns but I thought there might be a simple CSS way to do it.

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46

1 Answers1

0

Thanks @divy3993 for the link: https://w3bits.com/labs/flexbox-masonry/2/ It's a lot easier to google about this once you realize the coined term is 'Masonry'.

The parent container (.container in my example) has the styles:

.masonry { 
  display: flex;
  flex-flow: column wrap;
  max-height: 800px;
  margin-left: -8px; /* Adjustment for the gutter */
  width: 100%;
}

The bricks should also have a little spacing (.item in my example):

.masonry-brick {
  margin: 0 8px 8px 0; /* Some gutter */
}

This solution is pretty limited as a max-height value is required as the items are essentially wrapping column to column. However, a simple-ish fix is to add javascript that calculates the height of the items. Various methods can be used to do this.

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46