March 10, 2014 9:25 am

How to create Full Screen Responsive Image Gallery using CSS and Masonry

In this tutorial I am going to show you how to create a full screen responsive image gallery using CSS and Masonry ( is a JavaScript grid layout library ), I am giving you image gallery example but you can create your blog posts, user profiles, video wall etc using this technique so we are giving you this tutorial with a nice demo and source to download for free.

How to create Full Screen Responsive Image Gallery using CSS and Masonry

[wpdm_file id=89]DEMO

Read more:

How to create Responsive Header Menu with CSS

How to create Mobile Navigation Menu with CSS & jQuery

Step 1:

Create a grid and add images with different sizes.

<div id="container">
    <div class="grid-sizer"></div>
    <div class="item">
        <img src="http://placekitten.com/650/450" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/650/750" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1650/1250" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/850/450" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/900/700" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/700/1400" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1200/1300" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/750/650" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1600/900" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/700/400" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1100/1200" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/800/1100" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/600/400" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1100/900" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1320/1200" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
    <div class="item">
        <img src="http://placekitten.com/1024/768" class="image">
        <a class="onhandover" href="#">
            <h3 class="title">Your Image Title</h3>
            <div class="description">
                <p>
                    Description Goes here!!
                </p>
            </div>
        </a>
    </div>
</div>

Above markup create images grid with title and description with images placeholder for fast images delivery http://placekitten.com/1024/768 placekitten.com is A quick and simple service for getting pictures of kittens for use as placeholders in your designs or code.

CSS to organize your gallery:

<style>
.item {
    float: left;
    position: relative;
    line-height: 1em;
}

.grid-sizer { width: 20%; }
.item { width: 20%; }

@media screen and (max-width: 1224px) {
  /* 10 columns for larger screens */
  .grid-sizer { width: 33.33%; }
  .item { width: 33.33%; }
}

@media screen and (max-width: 720px) {
  /* 10 columns for larger screens */
  .grid-sizer { width: 50%; }
  .item { width: 50%; }
}

@media screen and (max-width: 480px) {
  /* 10 columns for larger screens */
  .grid-sizer { width: 100%; }
  .item { width: 100%; }
}

.image{
    max-width: 100%;
    margin: 0;
    display: block;
}

.image:after {
    clear:both;
}

.onhandover {
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    position: absolute;
    top: 0;
    left: 0;
    text-decoration: none;
    color: #fff;
    display: none;
}

.onhandover .title {
    text-align: center;
    font-size: 30px;
}

.onhandover .description {
    position: absolute;
    bottom: 0;
    left: 0;
    background-color: rgba(0,0,0,0.80);
    width: 100%;
    margin: 0;
}

.onhandover .description p {
    text-align: center;
}

.item:hover .onhandover {
    display: block;
}
</style>

We used @media for different screens to make gallery responsive and .onhandover class to show title and description oh handover event.

jQuery files to Include:

<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://demo.phpgang.com/full-screen-image-gallery-css-masonry/masonry.pkgd.min.js"></script>

Initialize Masonry using the following:

<script type="text/javascript">
$(window).load( function() {

    $("#container").masonry({
        "itemSelector": ".item",
        "columnWidth": ".grid-sizer",
    });

});
</script>
[wpdm_file id=89]DEMO

That’s all for today’s tutorial I hope you like this tutorial please don’t forget to give us your feedback and share with your friends.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:

One response to “How to create Full Screen Responsive Image Gallery using CSS and Masonry”

  1. i have already use masonry.js jquery library!in my blog but this one is amazing using responsive type site!

    amazing demo!

    http://www.i-visionblog.com/2014/01/working-with-masonryjs-for-aligning.html

Leave a Reply

Your email address will not be published. Required fields are marked *