cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <h1>Isotope - layout modes</h1>

<div class="button-group layout-mode-button-group">
  <button class="button is-checked" data-layout-mode="masonry" checked="checked">masonry</button>
  <button class="button" data-layout-mode="fitRows">fitRows</button>
  <button class="button" data-layout-mode="cellsByRow">cellsByRow</button>
  <button class="button" data-layout-mode="vertical">vertical</button>
  <button class="button" data-layout-mode="packery">packery</button>
  <button class="button" data-layout-mode="masonryHorizontal" data-is-horizontal="true">masonryHorizontal</button>
  <button class="button" data-layout-mode="fitColumns" data-is-horizontal="true">fitColumns</button>
  <button class="button" data-layout-mode="cellsByColumn" data-is-horizontal="true">cellsByColumn</button>
  <button class="button" data-layout-mode="horiz" data-is-horizontal="true">horiz</button>
</div>

<div class="grid">
  <div class="grid-item grid-item--width2">1</div>
  <div class="grid-item grid-item--height2">2</div>
  <div class="grid-item">3</div>
  <div class="grid-item">4</div>
  <div class="grid-item grid-item--width2 grid-item--height2">5</div>
  <div class="grid-item grid-item--width2">6</div>
  <div class="grid-item grid-item--height2">7</div>
  <div class="grid-item">8</div>
  <div class="grid-item">9</div>
  <div class="grid-item grid-item--width2">10</div>
  <div class="grid-item">11</div>
  <div class="grid-item">12</div>
</div>

            
          
!
            
              * { box-sizing: border-box; }

body {
  font-family: sans-serif;
}

/* ---- button ---- */

.button {
  display: inline-block;
  padding: 0.5em 1.0em;
  background: #EEE;
  border: none;
  border-radius: 7px;
  background-image: linear-gradient( to bottom, hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 0.2) );
  color: #222;
  font-family: sans-serif;
  font-size: 16px;
  cursor: pointer;
}

.button:hover {
  background-color: #8CF;
  color: #222;
}

.button:active,
.button.is-checked {
  background-color: #28F;
}

.button.is-checked {
  color: white;
}

.button:active {
  box-shadow: inset 0 1px 10px hsla(0, 0%, 0%, 0.8);
}

/* ---- button-group ---- */

.button-group {
  margin-bottom: 20px;
}

.button-group:after {
  content: '';
  display: block;
  clear: both;
}

.button-group .button {
  float: left;
  border-radius: 0;
  margin-left: 0;
  margin-right: 1px;
}

.button-group .button:first-child { border-radius: 0.5em 0 0 0.5em; }
.button-group .button:last-child { border-radius: 0 0.5em 0.5em 0; }

/* ---- grid ---- */

.grid {
  border: 1px solid #333;
}

/* clear fix */
.grid:after {
  content: '';
  display: block;
  clear: both;
}

/* ---- .element-item ---- */

.grid-item {
  position: relative;
  float: left;
  width: 100px;
  height: 100px;
  margin: 5px;
  padding: 10px;
  background: red;
  color: white;
  font-size: 50px;
}

.grid-item--width2 { width: 210px; }
.grid-item--height2 { height: 210px; }

.grid-item:nth-child(10n+0) { background: hsl(   0, 100%, 50%); }
.grid-item:nth-child(10n+1) { background: hsl(  36, 100%, 50%); }
.grid-item:nth-child(10n+2) { background: hsl(  72, 100%, 50%); }
.grid-item:nth-child(10n+3) { background: hsl( 108, 100%, 50%); }
.grid-item:nth-child(10n+4) { background: hsl( 144, 100%, 50%); }
.grid-item:nth-child(10n+5) { background: hsl( 180, 100%, 50%); }
.grid-item:nth-child(10n+6) { background: hsl( 216, 100%, 50%); }
.grid-item:nth-child(10n+7) { background: hsl( 252, 100%, 50%); }
.grid-item:nth-child(10n+8) { background: hsl( 288, 100%, 50%); }
.grid-item:nth-child(10n+9) { background: hsl( 324, 100%, 50%); }

            
          
!
            
              // external js: isotope.pkgd.js, cells-by-column.js, cells-by-row.js, fit-columns.js, horizontal.js, masonry-horizontal.js

// init Isotope
var $grid = $('.grid').isotope({
  itemSelector: '.grid-item',
  layoutMode: 'masonry',
  masonry: {
    columnWidth: 110
  },
  cellsByRow: {
    columnWidth: 220,
    rowHeight: 220
  },
  masonryHorizontal: {
    rowHeight: 110
  },
  cellsByColumn: {
    columnWidth: 220,
    rowHeight: 220
  }
});

var isHorizontal = false;
var $window = $( window );

$('.layout-mode-button-group').on( 'click', 'button', function() {
  // adjust container sizing if layout mode is changing from vertical or horizontal
  var $this = $(this);
  var isHorizontalMode = !!$this.attr('data-is-horizontal');
  if ( isHorizontal !== isHorizontalMode ) {
    // change container size if horiz/vert change
    var containerStyle = isHorizontalMode ? {
      height: $window.height() * 0.7
    } : {
      width: 'auto'
    };
    $grid.css( containerStyle );
    isHorizontal = isHorizontalMode;
  }
  // change layout mode
  var layoutModeValue = $this.attr('data-layout-mode');
  $grid.isotope({ layoutMode: layoutModeValue });
});  

// change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
  var $buttonGroup = $( buttonGroup );
  $buttonGroup.on( 'click', 'button', function() {
    $buttonGroup.find('.is-checked').removeClass('is-checked');
    $( this ).addClass('is-checked');
  });
});

            
          
!
999px
Loading ..................

Console