Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html ng-app="test">
<head>
    <title>Bootstrap + Masonry Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div ng-view ng-controller="ctrl">
<div class="row" style="margin-top:50px" masonry='{"transitionDuration": "0.4s", "itemSelector": ".buttonBlock"}'>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="orange-btn ownThumbnail thumbnailContent">
            <p>Item 1</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="orange-btn ownThumbnail thumbnailContent">
            <p>Item 2</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail orange-btn thumbnailContent">
            <p>Item 3</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail orange-btn thumbnailContent">
            <p>Item 4</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail orange-btn thumbnailContent">
            <p>Item 5</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="1">
        <a href="#" class="ownThumbnail green-btn thumbnailContent">
            <p>Item 6</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="light-orange-btn ownThumbnail thumbnailContent">
            <p>Item 7</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="light-orange-btn ownThumbnail thumbnailContent">
            <p>Item 8</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail light-orange-btn thumbnailContent">
            <p>Item 9</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail light-orange-btn thumbnailContent">
            <p>Item 10</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail light-orange-btn thumbnailContent">
            <p>Item 11</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="green-btn ownThumbnail thumbnailContent">
            <p>Item 12</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="yellow-btn ownThumbnail thumbnailContent">
            <p>Item 13</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail yellow-btn thumbnailContent">
            <p>Item 14</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail yellow-btn thumbnailContent">
            <p>Item 15</p>
        </a>
    </div>
    <div class="col-lg-2 col-sm-3 col-xs-6 buttonBlock" data-bind-height-to-width="0.5">
        <a href="#" class="ownThumbnail yellow-btn thumbnailContent">
            <p>Item 16</p>
        </a>
    </div>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://masonry.desandro.com/masonry.pkgd.min.js"></script>
</body>
</html>
              
            
!

CSS

              
                @import "lesshat";

.orange-btn {
    background-color: orange;
    height: 100%;
    width: 100%;
}

.orange-btn:hover, .orange-btn:active, .orange-btn:focus {
    background-color: darken(orange, 10%);
}

.yellow-btn {
    background-color: yellow;
    height: 100%;
    width: 100%;
}

.yellow-btn:hover {
    background-color: darken(yellow, 10%);
}

.green-btn {
    background-color: green;
    height: 100%;
    width: 100%;
}

.green-btn:hover {
    background-color: darken(green, 10%);
}

.light-orange-btn {
    background-color: lighten(orange, 20%);
    height: 100%;
    width: 100%;
}

.light-orange-btn:hover {
    background-color: lighten(orange, 10%);
    color: black;
}

.buttonBlock {
    margin-bottom: 10px;
    display: table;
}

.ownThumbnail {
    padding: 4px;
    line-height: 1.42857143;
    display: block;
    margin-bottom: 20px;
    color: black;
}

.ownThumbnail:hover {
    color: black;
    border: none;
}

.ownThumbnail.active {
    background-color: gray;
    color: black;
}

.ownThumbnail, .ownThumbnail i, .ownThumbnail p {
    color: black;
}

a[disabled].ownThumbnail, a[disabled].ownThumbnail i, a[disabled].ownThumbnail p {
    background-color: #ccc;
    color: gray;
}

.thumbnailContent {
    text-align: center;
    display: table-cell;
    vertical-align: middle;
}

.thumbnailContent i {
    margin-top: 2px;
}

.thumbnailContent p {
    padding-top: 2px;
    text-transform: uppercase;
    font-size: 0.89em;
}

              
            
!

JS

              
                testModule = angular.module('test', []);

testModule.controller('ctrl', function($scope) {
    window.setTimeout(function() {
        $scope.$apply(function() {
            $scope.testTiles = [];

            for (var i = 0; i < 10; i++) {
                $scope.testTiles.push(i);
            }            

            $scope.update(); //update masonry layout
        })
    }, 1000)
});

testModule.directive('masonry', function ($parse) {
    return {
        restrict: 'AC',
        link: function (scope, elem, attrs) {
            scope.items = [];
            var container = elem[0];
            var options = angular.extend({
                itemSelector: '.item'
            }, JSON.parse(attrs.masonry));

            var masonry = scope.masonry = new Masonry(container, options);

            var debounceTimeout = 0;
            scope.update = function () {
                if (debounceTimeout) {
                    window.clearTimeout(debounceTimeout);
                }
                debounceTimeout = window.setTimeout(function () {
                    debounceTimeout = 0;

                    masonry.reloadItems();
                    masonry.layout();

                    elem.children(options.itemSelector).css('visibility', 'visible');
                }, 120);
            };
        }
    };
}).directive('masonryTile', function () {
    return {
        restrict: 'AC',
        link: function (scope, elem) {
            elem.css('visibility', 'hidden');
            var master = elem.parent('*[masonry]:first').scope(),
                update = master.update;

            imagesLoaded(elem.get(0), update);
            elem.ready(update);
        }
    };
});

testModule.directive('bindHeightToWidth', function(){
    var directive = {
        restrict: 'A',
        link: function (scope, instanceElement, instanceAttributes, controller, transclude) {
            var heightFactor = 1;

            if (instanceAttributes['bindHeightToWidth']) {
                heightFactor = instanceAttributes['bindHeightToWidth'];
            }

            var updateHeight = function () {
                instanceElement.height(instanceElement.width() * heightFactor);
            };

            scope.$watch(instanceAttributes['bindHeightToWidth'], function (value) {
                heightFactor = value;
            });

            $(window).resize(updateHeight);
            updateHeight();

            scope.$on('$destroy', function () {
                $(window).unbind('resize', updateHeight);
            });
        }
    };

    return directive;
});
              
            
!
999px

Console