Is there a way to make my block-elements behave like in this example:
Desired effect:
|----|----|
|1111|2222|
|1111|----|
|1111|3333|
|----|----|
|4444|
|----|
Actual result:
|----|----|
|1111|2222|
|1111|----|
|1111|
|----|----|
|3333|4444|
|----|----|
.wrapper {
background-color:red;
width:220px;
}
.block {
background-color:blue;
height:100px;
width:100px;
display:inline-block;
vertical-align:top;
margin:4px;
}
.long {
height:200px;
}
<div class="wrapper">
<div class="block long">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
I think best option for this is to use masonry plugin.
$('.wrapper').masonry({
columnWidth: 1,
itemSelector: '.block'
});
.wrapper {
background-color:red;
width:220px;
}
.block {
background-color:blue;
height:100px;
width: 100px;
display: inline-block;
margin:4px;
}
.long {
height:180px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/masonry.pkgd.min.js"></script>
<div class="wrapper">
<div class="block long"></div><div class="block"></div><div class="block"></div><div class="block"></div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With