Hey there ! Used Pinterest and love that fluid image layout ? Well you could easily create a similar layout with Bootstrap. In this post we would be creating an image layout similar to the one in Pinterest and we would be doing this with Bootstrap and Picturebox (a jQuery Lightbox plugin). The output that we create would be completely responsive and fluid. So alright lets dive into the topic.
Prerequisites :
- Bootstrap
- Picturebox Plugin
- Text Editor
- And some sample images
Getting Started with The Code :
Ok so lets get started with the code. Create a folder on your desktop and open it up. Copy the Bootstrap.css file that you just downloaded into this folder. And also paste folders images and includes that was present in the Picturebox plugin that you just downloaded. Now just create a couple of files in the folder and name it as index.html and another one as pinterest.css. Keep the pinterest.css file in your includes folder. We would first be dealing with the index.html file. So open it up and type in the following code and this would link the script files and the css files that we would be using.
<link rel = "stylesheet" href = "bootstrap.css">We would be using Bootstrap's grid system in this project. You might be familiar with that but still its worth explaining. Bootstrap's grid system divides the entire width of your browser into 12 columns which would arrange itself depending on the width of the window. To make use of the Bootstrap grid just create a class called container which would be the grand parent class and a class named rows which would be the parent class. We would be creating four child columns each with a class col-md-3 and the 3 here implies that we are combining 3 of those 12 columns and making that into a single column. And so we would now have 4 columns and each of them would be a combination of 3 columns which we spoke about early. So below is the code that would create what we spoke now.
<link rel = "stylesheet" href = "includes/picturebox.css">
<script src = "includes/jquery.js"></script>
<script src = "includes/picturebox.js"></script>
<div class = "container">
<div class = "row">
<div class = "col-md-3"></div>
<div class = "col-md-3"></div>
<div class = "col-md-3"></div>
<div class = "col-md-3"></div>
</div>
</div>
Now lets fill these columns with images. The first child div corresponds to the first column of images, the second child div the second column of images and so on. So lets fill it up and the end code would look something like below.
<div class = "container">
<div class = "row">
<div class = "col-md-3">
<img src = "images/1.jpg">
<img src = "images/2.jpg">
<img src = "images/3.jpg">
<img src = "images/4.jpg">
</div>
<div class = "col-md-3">
<img src = "images/5.jpg">
<img src = "images/6.jpg">
<img src = "images/7.jpg">
<img src = "images/8.jpg">
<img src = "images/9.jpg">
<img src = "images/10.jpg">
</div>
<div class = "col-md-3">
<img src = "images/11.jpg">
<img src = "images/12.jpg">
<img src = "images/13.jpg">
<img src = "images/14.jpg">
</div>
<div class = "col-md-3">
<img src = "images/16.jpg">
<img src = "images/17.jpg">
<img src = "images/18.jpg">
<img src = "images/19.jpg">
<img src = "images/20.jpg">
<img src = "images/15.jpg">
</div>
</div>
</div>
And so the final task we need to do with the index.html file is integrating this with the Picturebox plugin. To do that cover the image tags with a div of class lightbox. That's it. Its really so simple to integrate the Picturebox plugin. The entire index.html file would look like the following :
index.html file :
<link rel = "stylesheet" href = "includes/bootstrap.css">You could see that we have added an extra class to the div with the class container called imggrid. So the entire index.html file is now done. Lets now add some code the pinterest.css file and lets complete the task. Add the following code to the css file.
<link rel = "stylesheet" href = "includes/picturebox.css">
<script src = "includes/jquery.js"></script>
<script src = "includes/picturebox.js"></script>
<title>Pinterest Style Image Gallery</title>
<div class = "container imggrid">
<div class = "row">
<div class = "col-md-3">
<div class = "lightbox">
<img src = "images/1.jpg">
<img src = "images/2.jpg">
<img src = "images/3.jpg">
<img src = "images/4.jpg">
</div>
</div>
<div class = "col-md-3">
<div class = "lightbox">
<img src = "images/5.jpg">
<img src = "images/6.jpg">
<img src = "images/7.jpg">
<img src = "images/8.jpg">
<img src = "images/9.jpg">
<img src = "images/10.jpg">
</div>
</div>
<div class = "col-md-3">
<div class = "lightbox">
<img src = "images/11.jpg">
<img src = "images/12.jpg">
<img src = "images/13.jpg">
<img src = "images/14.jpg">
</div>
</div>
<div class = "col-md-3">
<div class = "lightbox">
<img src = "images/16.jpg">
<img src = "images/17.jpg">
<img src = "images/18.jpg">
<img src = "images/19.jpg">
<img src = "images/20.jpg">
<img src = "images/15.jpg">
</div>
</div>
</div>
</div>
</body>
body {So its all done now and your Pinterest style image layout is now ready ! Just open up the index.html file in the browser and you could see the awesome Pinterest style image layout in your browser ! Try resizing your browser and take a look at the responsiveness of the layout. Good looking right ? And you can download the source code or see the live demo below.
background-color: #0072c5;
color: #fff;
font-family: Lato;
font-weight: 700;
font-size: 50px;
}
.imggrid img {
width: 100%;
margin-bottom: 15px;
}
I used the following book to learn Twitter Bootstrap and its really awesome. Wanna know more about Bootstrap ? Then make sure you check out the following book.

So leave your doubts if any in the comments section. Happy designing :)













