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
Post a Comment