Align DIV dynamically like a stained glass window

Asked

Viewed 62 times

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 together as if they were forming a stained glass window. I did 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 white 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: http://tiredopapel.org/wp-content/uploads/2015/06/Google_Keep_Web_Update-630x484.png

1 answer

1


I made an example on jsFddle for you to understand the operation, but I’ll also put here:

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

.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>

  • Dude, I got it I did some tests here and got very close to what I want, I’m going to go right there Thanks David Damasceno

  • Calm man, if you agree with what you wanted, please mark the answer as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.