html - Creating a Masonry Layout using CSS? -
this question has answer here:
- masonry-style layout css 3 answers
i want create layout using css , not jquery or javascript. possible , if so, please direct me right source. :)
i tried hand @ didn't come out well: http://codepen.io/anon/pen/gjzwox
html:
<div class="parent"> <div class="red"> </div> <div class="blue"> </div> <div class="red"> </div> <div class="red"> </div> </div>
css:
.parent{ width:330px; } .red{ float:left; width:150px; height:150px; margin-bottom:10px; margin-left:10px; background-color:red; } .blue{ float:left; width:150px; height:300px; margin-bottom:10px; margin-left:10px; background-color:blue; }
flexbox allows due hability distribute content , gaps.
flexbox use not easy not imposible. here help: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.parent{ background: green; width:330px; height: 330px; display: flex; flex-flow: column wrap; } .red, .blue{ margin: 10px; } .red{ flex: 1 1 100px;; background-color:red; } .blue{ flex: 2 2 150px; background-color:blue; }
here pen you:http://codepen.io/vandervals/pen/ovnvae?editors=110
so, explanation of happening here follows:
the parent must have
display: flex
.you have tell flow direction, in case want columns.
for items, have define flex properties. in case, want red smaller, proportion 1 , tendency 100px if can. blue has double "weight" , tendency 150px.
Comments
Post a Comment