css - How to fill the white spaces out with divs -


how fill white spaces out divs?

i need divs behave each of them fill out white spaces. so, if needed, div goes top, joining div above, this, wherever if use float: left or display: inline-block/inline

main {    font-size: 0;  }  main > div {    width: 25%;    display: inline-block;    vertical-align: top;  }  main > div:nth-child(4n+1) {    height: 200px;    background: red;  }  main > div:nth-child(4n+2) {    height: 100px;    background: blue;  }  main > div:nth-child(4n+3) {    height: 300px;    background: orange;  }  main > div:nth-child(4n+4) {    height: 150px;    background: darkcyan;  }
<main>    <div></div>    <div></div>    <div></div>    <div></div>        <div></div>    <div></div>    <div></div>    <div></div>        <div></div>    <div></div>    <div></div>    <div></div>      </main>

in order achieve layout need use javascript logic.
css alone not allow position elements of different heights that.

one recommendation masonry heaving lifting , calculate appropriate position elements , apply position: absolute; , set top , left css properties on them.

masonry javascript grid layout library. works placing elements in optimal position based on available vertical space, sort of mason fitting stones in wall. you’ve seen in use on internet.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -