DIV align dynamically as a stained glass window

0

Good afternoon

I'm on a personal project and one of my inspirations is the Google Keep layout, where the divs line up and fit like they're forming a stained glass window. I made some tests aligning the divs to the left (float: left), but the divs always respect the height of the end of the largest div that is already on the screen, and there is a space in some places.

Does anyone have any idea how to do this kind of alignment? For a better idea of what I'm talking about, take a look at this image: link

    
asked by anonymous 11.04.2016 / 22:06

1 answer

1

I made an example in the jsFddle to understand the operation, but I'll also put it here:

Basically, you control the columns with the column-count and column-gap CSS tags.

.geral{padding: 5px;height: 390px;}
.collum{   
-webkit-column-count: 5;
-webkit-column-gap: 0px;
-webkit-column-fill: auto;
 -moz-column-count: 5;
-moz-column-gap: 5px;
-moz-column-fill: auto;
column-count: 5;
column-gap: 0px;
column-fill: auto;}

.quadrado{width: 100px; height: 150px; background: orange; margin-bottom: 10px; margin-left: 10px;    display: inline-block;
}
.um{height: 130px}
.dois{height: 180px}
.tres{height: 120px}
.quatro{height: 100px;}
<div class="geral">
  <div class="collum">
      <div class="quadrado"></div>
      <div class="quadrado um"></div>
      <div class="quadrado dois"></div>
      <div class="quadrado"></div>
      <div class="quadrado"></div>
      <div class="quadrado tres"></div>
      <div class="quadrado"></div>
      <div class="quadrado quatro"></div>
      <div class="quadrado"></div>
      <div class="quadrado"></div>
  </div>
</div>
    
11.04.2016 / 23:15