How to group elements dynamically indepente the size?

Asked

Viewed 587 times

1

I have a div parent who is responsible for bringing together certain quantities of children.

The problem is that this div is always aligned to the left, without leaving blank spaces, but each parent div has a different number of child elements.

This causes each parent div to have a different height, and consequently the float: left In some cases it causes an element to be aligned to the right, leaving a huge blank to the left. When there’s no white space on top.

I will illustrate the problem I have with two images:

Problem

Os items deveriam ficar flexíveis, porém estão deixando um espaço indesejado

Os items deveriam ficar flexíveis, porém estão deixando um espaço indesejado

Desired solution

inserir a descrição da imagem aqui

  • 1

    Like the Pinterest site ?

  • Exact lover, @Diegosouza

  • 1

    Once I needed it I used a jQuery plugin. If you are interested here: http://www.jqueryscript.net/demo/Masonry-style-Fluid-Image-Grid-Plugin-For-jQuery-fluid/. You may already have searched.

1 answer

-1

try to use the following markup HTML that should work:

#conteudo {
  float: left;
  width: 80%;
  height: 400px:
}
#barra-lateral {
  float: right;
  width: 20%;
  height: 400px;:
}

.item {
  background-color: red;
  display: inline-block;
  margin: 10px;
}

#conteudo .item {
  width: 100px;
  height: 100px;
}

#barra-lateral .item {
  width: 95%;
  height: 95%
}
<div id="conteudo">
  <div class="item">1</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
</div>
<div id="barra-lateral">
  <div class="item">2</div>
</div>

Browser other questions tagged

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