Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1>Grid Layout by Muuri.js</h1>

<section class="grid-wrapper">
  <div class="filter-controls">
    <div class="control">Search
      <input class="search-field form-control" type="text" name="search" placeholder="Enter the fruit name">
    </div>
    <div class="control">Filter
      <select class="filter-field form-control">
        <option value="">None</option>
        <option value="red">Red</option>
        <option value="blue">Blue</option>
        <option value="green">Green</option>
      </select>
    </div>
    <div class="control">Sort
      <select class="sort-field form-control">
        <option value="order">None</option>
        <option value="title">Order by fruit name</option>
        <option value="color">Order by color name</option>
      </select>
    </div>
  </div>

  <div class="grid">
    <div class="item blue w2 h2" data-color="blue" data-title="peach">
      <div class="item-content">
        <!-- Safe zone, enter your custom markup -->
          <div class="custom-content">
          Item 1<br />(peach)
          </div>
        <!-- Safe zone ends -->
      </div>
    </div>
    <div class="item red w2" data-color="red" data-color="blue" data-title="orange">
      <div class="item-content">
        <div class="custom-content">
          Item 2<br />(orange)
        </div>
      </div>
    </div>
    <div class="item green w2" data-color="green" data-color="blue" data-title="banana applpe">
      <div class="item-content">
        <div class="custom-content">
          Item 3<br />(banana apple)
        </div>
      </div>
    </div>
    <div class="item red w2 h2" data-color="red" data-color="blue" data-title="grape orange">
      <div class="item-content">
        <div class="custom-content">
          Item 4<br />(grape orange)
        </div>
      </div>
    </div>
    <div class="item red" data-color="red" data-color="blue" data-title="strawberry">
      <div class="item-content">
        <div class="custom-content">
          Item 5<br />(strawberry)
        </div>
      </div>
    </div>
    <div class="item blue" data-color="blue" data-color="blue" data-title="cherry banana">
      <div class="item-content">
        <div class="custom-content">
          Item 6<br />(cherry banana)
        </div>
      </div>
    </div>
    <div class="item red h2" data-color="red" data-color="blue" data-title="melon apple">
      <div class="item-content">
        <div class="custom-content">
          Item 7<br />(melon apple)
        </div>
      </div>
    </div>
    <div class="item green h2" data-color="green" data-color="blue" data-title="kiwi">
      <div class="item-content">
        <div class="custom-content">
          Item 8<br />(kiwi)
        </div>
      </div>
    </div>
    <div class="item green w2" data-color="green" data-color="blue" data-title="watermelon">
      <div class="item-content">
        <div class="custom-content">
          Item 9<br />(watermelon)
        </div>
      </div>
    </div>
    <div class="item blue w2 h2" data-color="blue" data-color="blue" data-title="pineapple">
      <div class="item-content">
        <div class="custom-content">
          Item 10<br />(pineapple)
        </div>
      </div>
    </div>
    <div class="item green" data-color="green" data-color="blue" data-title="blueberry">
      <div class="item-content">
        <div class="custom-content">
          Item 11<br />(blueberry)
        </div>
      </div>
    </div>
    <div class="item red h2" data-color="red" data-color="blue" data-title="peach">
      <div class="item-content">
        <div class="custom-content">
          Item 12<br />(peach)
        </div>
      </div>
    </div>
    <div class="item blue w2" data-color="blue" data-color="blue" data-title="lemon">
      <div class="item-content">
        <div class="custom-content">
          Item 13<br />(lemon)
        </div>
      </div>
    </div>
    <div class="item blue w2" data-color="blue" data-color="blue" data-title="grapefruit">
      <div class="item-content">
        <div class="custom-content">
          Item 14<br />(grapefruit)
        </div>
      </div>
    </div>
    <div class="item green" data-color="green" data-color="blue" data-title="guava">
      <div class="item-content">
        <div class="custom-content">
          Item 15<br />(guava)
        </div>
      </div>
    </div>
    <div class="item red w2" data-color="red" data-color="blue" data-title="yellowstrawberry">
      <div class="item-content">
        <div class="custom-content">
          Item 16<br />(yellowstrawberry)
        </div>
      </div>
    </div>
    <div class="item green" data-color="green" data-color="blue" data-title="avocado">
      <div class="item-content">
        <div class="custom-content">
          Item 17<br />(avocado)
        </div>
      </div>
    </div>
    <div class="item green w2" data-color="green" data-color="blue" data-title="grape">
      <div class="item-content">
        <div class="custom-content">
          Item 18<br />(grape)
        </div>
      </div>
    </div>
    <div class="item blue w2" data-color="blue" data-color="blue" data-title="peach banana">
      <div class="item-content">
        <div class="custom-content">
          Item 19<br />(peach banana)
        </div>
      </div>
    </div>
    <div class="item blue" data-color="blue" data-color="blue" data-title="grape">
      <div class="item-content">
        <div class="custom-content">
          Item 20<br />(grape)
        </div>
      </div>
    </div>
  </div>
</select>
              
            
!

CSS

              
                // ******************************
// Normalize (ignore me!)
// ******************************
@import url(//fonts.googleapis.com/css?family=Montserrat:9000);
$fonts:Arial,"Hiragino Kaku Gothic Pro W3",Meiryo,sans-serif;
$web_fonts:'Montserrat', sans-serif;
$bg_color:#fff;
$font_color:#999;
$link_color:#999;
$link_hover_color:#777;

* {
  &:before,
  &:after{
    box-sizing:border-box;
    padding:0;
    margin:0;
  }
}
body{
  font-family:$fonts;
  background-color:$bg_color;
  color: $font_color;
  text-align: center;
  a, a:visited{
    color: $link_color;
    text-decoration:none;
  }
  a:hover{
    color: $link_hover_color;
  }
}
// ******************************
// End of Normalize
// ******************************

h1{
  font-size:36px;
  font-family:$web_fonts;
  color:#53E2E4;
  margin:10px auto 30px;
}
.filter-controls{
  text-align:center;
  margin-bottom:30px;
  .control{
    display:inline-block;
    width:240px;
    margin:0 10px;
    *{
      box-sizing:border-box;
    }
    .form-control{
      width:100%;
      height:40px;
      padding:0 20px;
      border:2px solid #ccc;
      border-radius:3px;
      background-color:#fff;
      color:#666;
      font-size:16px;
      cursor:pointer;
      -webkit-appearance:none;
      appearance:none;
      &:focus{
        outline:0;
        border-color:#0CAAF5;
      }
    }
  }  
}

.grid {
  position: relative;
  width:878px;
  max-width:100%;
  margin:0 auto;
}
.item {
  position: absolute;
  width:99px;
  height:99px;
  margin: 5px;
  z-index: 1;
  transition:transform .6s ease;
  cursor:move;
  &.blue{
    .custom-content{
      border-color:#0CAAF5;
      color:#0CAAF5;
    }
  }
  &.red{
    .custom-content{
      border-color:#F54487;
      color:#F54487;
    }
  }
  &.green{
    .custom-content{
      border-color:#00DE73;
      color:#00DE73;
    }
  }
  &.w2{
    width:208px;
  }
  &.h2{
    height:208px;
  }
}
.item-content {
  position: relative;
  width: 100%;
  height: 100%;
  display:table;
}
.custom-content{
  display:table-cell;
  vertical-align:middle;
  text-align: center;
  background: #fff;
  color: #666;
  border:2px solid;
  border-radius:3px;
}

// If use dragging
.item.muuri-item-dragging {
  z-index: 3;
  transition:none;
}
.item.muuri-item-releasing {
  z-index: 2;
}

@media ( max-width : 877px ){
  .item{
    width:calc(33.33% - 11px);
    height:calc(33.33vw - 11px);
    &.w2{
      width:calc(33.33% - 11px);
    }
    &.h2{
      height:calc(33.33vw - 11px);
    }
  }
}
@media ( max-width : 640px ){
  .item{
    width:calc(50% - 10px);
    height:calc(50vw - 10px);
    &.w2{
      width:calc(50% - 10px);
    }
    &.h2{
      height:calc(50vw - 10px);
    }
  }
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', function () {
  var grid = null,
      wrapper = document.querySelector('.grid-wrapper'),
      searchField = wrapper.querySelector('.search-field'),
      filterField = wrapper.querySelector('.filter-field'),
      sortField = wrapper.querySelector('.sort-field'),
      gridElem = wrapper.querySelector('.grid'),
      searchAttr = 'data-title',
      filterAttr = 'data-color',
      searchFieldValue,
      filterFieldValue,
      sortFieldValue,
      dragOrder = [];

  // Init the grid layout
  grid = new Muuri(gridElem, {
    dragEnabled: true
  });
  
  // Set inital search query, active filter, active sort value and active layout.
  searchFieldValue = searchField.value.toLowerCase();
  filterFieldValue = filterField.value;
  sortFieldValue = sortField.value;

  // Search field event binding
  searchField.addEventListener('keyup', function () {
    var newSearch = searchField.value.toLowerCase();
    if (searchFieldValue !== newSearch) {
      searchFieldValue = newSearch;
      filter();
    }
  });

  // Filter field event binding
  filterField.addEventListener('change', filter);
  
  // Sort field event binding
  sortField.addEventListener('change', sort);

  // Filtering
  function filter() {
    filterFieldValue = filterField.value;
    grid.filter(function (item) {
      var element = item.getElement(),
          isSearchMatch = !searchFieldValue ? true : (element.getAttribute(searchAttr) || '').toLowerCase().indexOf(searchFieldValue) > -1,
          isFilterMatch = !filterFieldValue ? true : (element.getAttribute(filterAttr) || '') === filterFieldValue;
      return isSearchMatch && isFilterMatch;
    });
  }
  
  // Sorting
  function sort() {
    // Do nothing if sort value did not change.
    var currentSort = sortField.value;
    if (sortFieldValue === currentSort) {
      return;
    }

    // If we are changing from "order" sorting to something else
    // let's store the drag order.
    if (sortFieldValue === 'order') {
      dragOrder = grid.getItems();
    }

    // Sort the items.
    grid.sort(
      currentSort === 'title' ? compareItemTitle :
      currentSort === 'color' ? compareItemColor :
      dragOrder
    );
    sortFieldValue = currentSort;
  }
  
  // Compare data-title
  function compareItemTitle(a, b) {
    var aVal = a.getElement().getAttribute(searchAttr) || '';
    var bVal = b.getElement().getAttribute(searchAttr) || '';
    return aVal < bVal ? -1 : aVal > bVal ? 1 : 0;

  }

  // Compare data-color
  function compareItemColor(a, b) {
    var aVal = a.getElement().getAttribute(filterAttr) || '';
    var bVal = b.getElement().getAttribute(filterAttr) || '';
    return aVal < bVal ? -1 : aVal > bVal ? 1 : compareItemTitle(a, b);
  }
});
              
            
!
999px

Console