Pure CSS solution can be found in this jsfiddle
HTML
<div class="wrap">
<div class="flex-c">
<div class="flex-i big"></div>
<div class="flex-i red"></div>
<div class="flex-i big green"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
<div class="flex-i green"></div>
<div class="flex-i red"></div>
<div class="flex-i blue"></div>
</div>
</div>
CSS
.flex-c:after {
content: '';
display: table;
clear: both;
}
.flex-i.red { background-color: red; }
.flex-i.blue {background-color: blue; }
.flex-i.green {background-color: green;}
.flex-i {
transform: rotate(90deg) scaleY(-1);
height: 100px;
width: 100px;
background-color: gray;
margin: 0 10px 10px 0;
float: left;
}
.flex-i:after,
.flex-i.big:before {
content: '';
height: 100px;
width: 100px;
left: 110px;
top: 0;
position: absolute;
background-color: pink;
}
.flex-i.big:after {
left: 220px;
}
.flex-i.big:before {
left: 220px;
bottom: 0;
top: auto;
}
.big {
width: 210px;
height: 210px;
}
Additionally
You may be able to benefit from using a library such as Isotopes JS masonry layout
It assists you to produce a layout style that you've shown.
Here is a working example.
HTML
<div id="container">
<div class="item"></div>
<div class="item w2"></div>
<div class="item"></div>
<div class="item w2"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item w2 h2"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item w2"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item h2"></div>
</div>
CSS
#container {
border: 1px solid;
padding: 7px;
}
.item {
width: 60px;
height: 60px;
float: left;
margin: 3px;
background: #CCC;
}
.item.w2 {
width: 130px;
}
.item.h2 {
height: 130px;
}
JS - note that you have to apply the masonry to the parent element, which in this case is the id of container
$( function() {
var $container = $('#container').masonry({
itemSelector: '.item',
columnWidth: 70
});
});
View the jsFiddle here