Skip to content
🐲 Examples illustrating a Pinterest like layout.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Pinterest layout

This coding-challenge was part of the interview process with Stylight (Munich, Germany) for a software engineer (frontend) role. Time frame was about 2 days.

Problem Statement

The problem statement can be found at here.

Pinterest layout

Examples illustrating a Pinterest like layout.

Example 1: CSS Only

Example 1

How to use

Include the neccesary Stylesheet file:

<link rel="stylesheet" type="text/css" href="styles.css" media="screen">

Include a simple div to hold the mosaic:

<div id="mosaic-container">


Demo Example 1

Example 2 & 3: JavaScript Example 2 & 3 implement a similar Pinterest layout as Example 1, but instead of using a pure CSS solution, they make use of pure JavaScript (except for the header and navigation controls). jQuery is not required.

Example 3 also includes a different header and provides a responsive navigation. That is, when the view port decreases in size, the top navigation disappears and a mobile friendly slide out navigation becomes available (see Example 3 illustration or test it using the available Demo Example 3).

Example 2
Example 3

How Mosaic works

The images are positioned dynamically by iterating through them and placing them at the bottom of whichever column has the shortest height at the moment. The column's height is then increased by the image's height (and some margins).

How to use Mosaic

Since Mosaic is purely JavaScript based, you only need to include the mosaic.js file:

<script type="text/javascript" src="mosaic.js"></script>

Include a simple div to hold the mosaic:

<div id="mosaic-container"></div>

Initialise Mosaic with an array of image paths:

  var mosaic = new JSMosaic('mosaic-container',['images/1.jpg','images/2.jpg','images/3.jpg','images/4.jpg','images/5.jpg','images/6.jpg', 'images/7.jpg','images/8.jpg','images/9.jpg','images/10.jpg','images/11.jpg','images/12.jpg']);

Public methods



Type: String

path of image to add.


Demo Example 2

Demo Example 3

You can’t perform that action at this time.