DIV A vertically floating div is sorted down by row

I am trying to find DIVs vertically from top to bottom inside a container. The container should be vertically limited to 500 pixels. All DIVs that cannot fit into this limit should be moved to the next line.

<style>
#container {
    position:relative;
    background-color:red;
    max-width:500px;
    min-height:500px;
    }
#area {
    position:absolute;
    bottom: 0;
    background-color:yellow;
    margin:20px;
    width:100px;
    height:100px;

}
</style>

<div id="container">
    <div id="area">area1</div>
    <div id="area">area2</div>
    <div id="area">area3</div>
    <div id="area">area4</div>
    <div id="area">area5</div>
    <div id="area">area6</div>
</div>

My line result should look like this:

    ---------------------------->
    | -------- --------
    | |Area 1| |Area 5|
    | -------- --------
    | -------- --------
max | |Area 2| |Area 6|
500 | -------- --------
 px | --------
    | |Area 3|   etc..
    | --------
    | --------             /\
    | |Area 4|   etc....... |
    | --------   
    --------------------------->

My questions are: what am I doing wrong, and if possible? Thanks!

+2
source share
3 answers

CSS columns at first seem like a promising solution, but they will not automatically adjust the width of the container as you add or remove areas.

, divs, , , . float:right. 90 , . divs , 90 .

- :

#container {
  position:relative;
  background-color:red;
  max-width:500px;
  margin-left:-500px;
  max-height:500px;
  overflow:hidden;
  -webkit-transform:rotate(-90deg);
  -webkit-transform-origin:top right;
  -ms-transform:rotate(-90deg);
  -ms-transform-origin:top right;
  transform:rotate(-90deg);
  transform-origin:top right;
  padding:20px 0 0 20px;
  -webkit-box-sizing:border-box;
  -moz-box-sizing:border-box;
  box-sizing:border-box;
}
#area {
  background-color:yellow;
  margin:0 20px 20px 0;
  width:100px;
  height:100px;
  float:right;
  -webkit-transform:rotate(90deg);
  -ms-transform:rotate(90deg);
  transform:rotate(90deg);
}

margin-left , - (.. max-width). max-height "", , . overflow:hidden , , .

, , div , . - ( ), box-sizing:border-box.

, divs 1:1, , , . , .

IE, , , IE9.

+2

, CSS, jsfiddle, CSS

     #container{
        position: relative;
        background-color: red;
        max-width: 500px;
        min-height: 500px;
        padding: 20px;

        -moz-box-sizing: border-box;
        box-sizing: border-box;

        -moz-column-width: 150px;
        -webkit-column-width: 150px;
        -o-column-width: 150px;
        column-width: 150px;
     }
     #area{
        background-color: yellow;
        display: inline-block;
        font: italic 45px/215px georgia;
        height: 215px;
        margin-bottom: 21px;
        text-align: center;
        width: 215px;
     }

.

, , , IE 10. , ALA IE.

0

    #container {
      background-color: red;
      max-width: 330px;
      max-height: 300px;
      padding: 20px;
      overflow:auto;
    }

    .area {
      background-color: yellow;
      display: inline-block;
      height: 70px;
      margin-bottom: 21px;
      text-align: center;
      width: 70px;
    }

    .x {
      background-color: cyan;
      height: 30px;
      width: 90px;
    }

    .Z {
      background-color: grey;
      height: 300px;
      width: 190px;
    }
    <div id="container">
      <div class="area">area1</div>
      <div class="area">area2</div>
      <div class="area x">area3</div>
      <div class="area">area4</div>
      <div class="area x">area5</div>
      <div class="area Z">area6</div>
    </div>
Hide result
0

Source: https://habr.com/ru/post/1524911/


All Articles