<div class="posts">
        <div class="posts__item">
            <img
              src="https://avatars.mds.yandex.net/get-zen_doc/1634555/pub_5cd9c1265631d800b3136b69_5cde8896c4964500b2b0e2d9/scale_1200"
              alt=""
            />
          </div><div class="posts__item">
            <img
              src="https://avatars.mds.yandex.net/get-zen_doc/1634555/pub_5cd9c1265631d800b3136b69_5cde8896c4964500b2b0e2d9/scale_1200"
              alt=""
            />
          </div><div class="posts__item">
            <img
              src="https://avatars.mds.yandex.net/get-zen_doc/1634555/pub_5cd9c1265631d800b3136b69_5cde8896c4964500b2b0e2d9/scale_1200"
              alt=""
            />
          </div><div class="posts__item">
            <img
              src="https://avatars.mds.yandex.net/get-zen_doc/1634555/pub_5cd9c1265631d800b3136b69_5cde8896c4964500b2b0e2d9/scale_1200"
              alt=""
            />
          </div>
      </div>
.posts__item {
  width: 50%;
}
.posts__item img {
  height: auto;
  width: 100%;
}
var grid = document.querySelector('.posts');
var msnry = new Masonry(grid, {
  itemSelector: '.posts__item',
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://masonry.desandro.com/masonry.pkgd.js
  2. https://rawgithub.com/desandro/classie/master/classie.js