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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                
<div class="c-hex-container">


  <ul class="c-hex-grid">

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item no-refresh">
      <a href="#" class="js-grid-refresh">
        <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Reload" alt="" />
      </a>
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

    <li class="c-hex-grid__item">
      <img class="c-hex-grid__media" src="http://placehold.it/200x230&text=Hex" alt="" />
    </li>

  </ul>
</div>

              
            
!

CSS

              
                // *************************************
//
//  Hex grid
//
// *************************************

* {
  box-sizing: border-box;
}

.js-grid-refresh:focus {
  outline: none;
}

// Our first row has 6 items in it, so we'll use that number to calculate
// some widths and spacing values
$hex-first-row-amount: 6;

// This component will take up the entire viewport width
$hex-container-width: 100vw;

$hex-small-bp: 768px;

.c-hex-container {
  overflow: hidden;
}

.c-hex-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 5000px;

  @media (max-width: #{$hex-small-bp}) {
    width: 100%;
  }
}


.c-hex-grid__item {
  float: left;
  width: 200px;
  width: calc(#{$hex-container-width} / #{$hex-first-row-amount});
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border-left: 2px solid #fff;
  border-right: 2px solid #fff;
  // Weird rendering bug when overflow: hidden; is on a clip path parent
  // this fixes it somehow
  transform: translateZ(0);

  @media (min-width: 1200px) {
    border-left: 4px solid #fff;
    border-right: 4px solid #fff;
  }

  @media (max-width: #{$hex-small-bp}) {
    width: calc(#{$hex-container-width} / #{$hex-first-row-amount / 3});
    margin-bottom: calc(#{$hex-container-width} / -#{$hex-first-row-amount * 1.25});
    &:nth-child(3n+1) {
      margin-left: calc(#{$hex-container-width} / #{$hex-first-row-amount / 1.5});
      clear: left;
      opacity: 0.4;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  &:hover {
    opacity: 0.4;
  }

  @media (min-width: #{$hex-small-bp}) {
    // These are the beginnings of new rows
    &:nth-child(7),
    &:nth-child(14) {
      clear: left;
    }

    // These are the hex items that overflow
    &:nth-child(1),
    &:nth-child(6),
    &:nth-child(7),
    &:nth-child(13),
    &:nth-child(14),
    &:nth-child(19) {
      opacity: 0.4;
      z-index: -1;
    }

    // Usually an even row that we need to offset to create the honeycomb pattern
    &:nth-child(n+7):nth-child(-n+13) {
      position: relative;
      left: -105px;
      left: calc(#{$hex-container-width}/-#{$hex-first-row-amount * 2});
      top: -58px;
      top: calc(#{$hex-container-width}/-#{$hex-first-row-amount * 4});
      margin-bottom: -111px;
      margin-bottom: calc(#{$hex-container-width}/-#{$hex-first-row-amount * 2});
    }
  }

}

.c-hex-grid__media {
  display: block;
  width: 100%;
}

              
            
!

JS

              
                /* jshint node:true */
/* globals TweenLite */

'use strict';

/**
 * This bastard of a thing
 * @type {Object}
 */
var HexGrid = {
  $container: $('.c-hex-container'),
  $refresh: $('.js-grid-refresh'),
  $gridItems: $('.c-hex-grid__item:not(.no-refresh)'),

  /**
   * Animation properties
   * @type {Object}
   */
  animation: {
    duration: 0.5,

    visible: {
      autoAlpha: 1,
      delay: 0.05,
      scale: 1
    },

    hidden: {
      autoAlpha: 0,
      scale: 0.8
    }
  },

  /**
   * Kick things off by watching for a refresh
   */
  init: function() {
    this.$refresh.on('click', this.refreshGrid);
  },

  /**
   * Try to recalculate positions if we need to
   * Probably most useful when grid isn't 100vw
   * but in some sort of container
   *
   * @return void
   */
  calculate: function() {
    var w = this.$container.width(),
        rowCount = 6,
        $newRow = $('.c-hex-grid__item:nth-child(n+7):nth-child(-n+13)');

    // TODO: Find some way to calculate correct border-widths

    // Setting with the width() method doesn't apply correct value
    $('.c-hex-grid__item').css('width', w / rowCount);

    // Calculations taken from Sass file
    $newRow.css({
      'left': w / -(rowCount * 2),
      'top': w / -(rowCount * 4),
      'margin-bottom': w / -(rowCount * 2)
    });
  },

  /**
   * Fancy-dancy animations
   *
   * @param  event e
   * @return void
   */
  refreshGrid: function(e) {
    var _ = HexGrid,
        i = 0;

    e.preventDefault();

    // Need to reset it on each call so we don't build up a long delay
    _.animation.visible.delay = 0.3;

    // Hide everything first
    TweenLite.to(_.$gridItems, _.animation.duration, _.animation.hidden);

    // Loop through and display with a small delay between each one
    // TODO: Maybe apply animations randomly
    for (i; i < _.$gridItems.length; i++) {
      _.animation.visible.delay += 0.05;
      TweenLite.to(_.$gridItems[i], _.animation.duration, _.animation.visible);
    }
  }
};

HexGrid.init();
              
            
!
999px

Console