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="demo-page">

  
  <section class="m-grid m-grid--divide-2 l-grid--divide-6">
    
    <div class="grid_field-unit">
      <div class="box-header">
        Ingrid 2.0 Demo
      </div>
    </div>
  
    <div class="grid_unit l-grid_unit--span-3">
      <article class="box">
        
        <div class="grid grid--divide-2">
          <div class="grid_unit">
            <div class="box-nested">
              boxen
            </div>
          </div>
          
          <div class="grid_unit">
            <div class="box-nested">
              boxen
            </div>
          </div>
        </div>
        
      </article>
    </div>
     
    <div class="grid_unit">
      <article class="box">
        boxen
      </article>
    </div>
    
    <div class="grid_unit">
      <article class="box">
        boxen
      </article>
    </div>
    
    <div class="grid_unit">
      <article class="box">
        boxen
      </article>
    </div>
   
  </section>
  
  <!-- non-responsive sectin -->
  
  <section class="grid grid--divide-4">
    
    <div class="grid_unit grid_unit--span-3">
      <article class="box-alt">
        boxen
      </article>
    </div>
     
    <div class="grid_unit">
      <article class="box-alt">
        boxen
      </article>
    </div>
  
  </section>
  
  
</div>
              
            
!

CSS

              
                


/* Ingrid 2.0 */

/*-----------------------------------------
 *
 * Author:   Robert Piirainen
 * Twitter:  @robertpiira
 * Github:   https://github.com/robertpiira/ingrid
 * Demo:     https://codepen.io/robertpiira/pen/kofpu
 * 
 *---------------------------------------*/

/*-----------------------------------------
 *
 * Mobile first approach for class names
 *
 * m-* class prefix is for "above small-sized viewports"
 * l-* class prefix is for "above medium-sized viewports"
 * 
 *---------------------------------------*/




/* INGRID - All
-----------------------------------------*/

.grid {
  letter-spacing: -0.31em;
}

.grid {
  padding: 0;
  list-style: none;
}

.grid_unit,
.grid_field-unit {
  margin: 0;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  letter-spacing: normal;
  word-spacing: normal;
}

.grid > .grid_unit {
  display: inline-block;
  vertical-align: top;
}

.grid_field-unit  {
  display: block;
}




/* GUTTERS - All
-----------------------------------------*/

.grid {
  margin: 0 -1rem;
}

.grid > .grid_unit,
.grid > .grid_field-unit {
  padding: 0 1rem;
}




/* UNITS - All
-----------------------------------------*/

.grid--divide-2  >  .grid_unit  { width: 50%; } 
.grid--divide-3  >  .grid_unit  { width: 33.33333%; }
.grid--divide-4  >  .grid_unit  { width: 25%; } 
.grid--divide-5  >  .grid_unit  { width: 20%; } 
.grid--divide-6  >  .grid_unit  { width: 16.66666%; }
.grid--divide-7  >  .grid_unit  { width: 14.28571%; }
.grid--divide-8  >  .grid_unit  { width: 12.5%; }




/* SPATIALS - All
-----------------------------------------*/

/* Spatial units in thirds */
.grid--divide-3  >  .grid_unit--span-2  { width: 66.66666%; }

/* Spatial units in fourths */
.grid--divide-4  >  .grid_unit--span-2  { width: 50%; }
.grid--divide-4  >  .grid_unit--span-3  { width: 75%; }

/* Spatial units in fifths */
.grid--divide-5  >  .grid_unit--span-2  { width: 40%; }
.grid--divide-5  >  .grid_unit--span-3  { width: 60%; }
.grid--divide-5  >  .grid_unit--span-4  { width: 80%; }

/* Spatial units in sixths */
.grid--divide-6  >  .grid_unit--span-2  { width: 33.33333%; }
.grid--divide-6  >  .grid_unit--span-3  { width: 50%; }
.grid--divide-6  >  .grid_unit--span-4  { width: 66.66666%; }
.grid--divide-6  >  .grid_unit--span-5  { width: 83.33333%; }

/* Spatial units in sevenths */
.grid--divide-7  >  .grid_unit--span-2  { width: 28.57142%; }
.grid--divide-7  >  .grid_unit--span-3  { width: 42.85714%; }
.grid--divide-7  >  .grid_unit--span-4  { width: 57.14285%; }
.grid--divide-7  >  .grid_unit--span-5  { width: 71.42857%; }
.grid--divide-7  >  .grid_unit--span-6  { width: 85.71428%; }

/* Spatial units in eights */
.grid--divide-8  >  .grid_unit--span-2  { width: 25%; }
.grid--divide-8  >  .grid_unit--span-3  { width: 37.5%; }
.grid--divide-8  >  .grid_unit--span-4  { width: 50%; }
.grid--divide-8  >  .grid_unit--span-5  { width: 62.5%; }
.grid--divide-8  >  .grid_unit--span-6  { width: 75%; }
.grid--divide-8  >  .grid_unit--span-7  { width: 87.5%; }




/* INGRID - Breakpoint
 * Above small-sized viewports
-----------------------------------------*/

@media only screen and (min-width: 480px) {
  
  .m-grid {
    padding: 0;
    list-style: none;
    letter-spacing: -0.31em;
  }
  
  .m-grid > .grid_unit {
    display: inline-block;
    vertical-align: top;
  }




  /* GUTTERS - Above small-sized viewports
  ---------------------------------------*/

  .m-grid {
    margin: 0 -1rem;
  }

  .m-grid > .grid_unit,
  .m-grid > .grid_field-unit {
    padding: 0 1rem;
  }
  



  /* UNITS - Above small-sized viewports
  ---------------------------------------*/

  .m-grid--divide-2  >  .grid_unit  { width: 50%; } 
  .m-grid--divide-3  >  .grid_unit  { width: 33.33333%; }
  .m-grid--divide-4  >  .grid_unit  { width: 25%; } 
  .m-grid--divide-5  >  .grid_unit  { width: 20%; } 
  .m-grid--divide-6  >  .grid_unit  { width: 16.66666%; }
  .m-grid--divide-7  >  .grid_unit  { width: 14.28571%; }
  .m-grid--divide-8  >  .grid_unit  { width: 12.5%; }



  /* SPATIALS - Above small-sized viewports
  ---------------------------------------*/

  /* Spatial units in thirds */
  .m-grid--divide-3  >  .m-grid_unit--span-2  { width: 66.66666%; }

  /* Spatial units in fourths */
  .m-grid--divide-4  >  .m-grid_unit--span-2  { width: 50%; }
  .m-grid--divide-4  >  .m-grid_unit--span-3  { width: 75%; }

  /* Spatial units in fifths */
  .m-grid--divide-5  >  .m-grid_unit--span-2  { width: 40%; }
  .m-grid--divide-5  >  .m-grid_unit--span-3  { width: 60%; }
  .m-grid--divide-5  >  .m-grid_unit--span-4  { width: 80%; }

  /* Spatial units in sixths */
  .m-grid--divide-6  >  .m-grid_unit--span-2  { width: 33.33333%; }
  .m-grid--divide-6  >  .m-grid_unit--span-3  { width: 50%; }
  .m-grid--divide-6  >  .m-grid_unit--span-4  { width: 66.66666%; }
  .m-grid--divide-6  >  .m-grid_unit--span-5  { width: 83.33333%; }

  /* Spatial units in sevenths */
  .m-grid--divide-7  >  .m-grid_unit--span-2  { width: 28.57142%; }
  .m-grid--divide-7  >  .m-grid_unit--span-3  { width: 42.85714%; }
  .m-grid--divide-7  >  .m-grid_unit--span-4  { width: 57.14285%; }
  .m-grid--divide-7  >  .m-grid_unit--span-5  { width: 71.42857%; }
  .m-grid--divide-7  >  .m-grid_unit--span-6  { width: 85.71428%; }

  /* Spatial units in eights */
  .m-grid--divide-8  >  .m-grid_unit--span-2  { width: 25%; }
  .m-grid--divide-8  >  .m-grid_unit--span-3  { width: 37.5%; }
  .m-grid--divide-8  >  .m-grid_unit--span-4  { width: 50%; }
  .m-grid--divide-8  >  .m-grid_unit--span-5  { width: 62.5%; }
  .m-grid--divide-8  >  .m-grid_unit--span-6  { width: 75%; }
  .m-grid--divide-8  >  .m-grid_unit--span-7  { width: 87.5%; }
  
}




/* INGRID - Breakpoint
 * Above medium-sized viewports
-----------------------------------------*/

@media only screen and (min-width: 768px) {
  
  .l-grid {
    padding: 0;
    list-style: none;
    letter-spacing: -0.31em;
  }
  
  .l-grid > .grid_unit {
    display: inline-block;
    vertical-align: top;
  }
  



  /* GUTTERS - Above medium-sized viewports
  ---------------------------------------*/
  
  .l-grid {
    margin: 0 -1rem;
  }
  
  .l-grid > .grid_unit,
  .l-grid > .grid_field-unit {
    padding: 0 1rem;
  }




  /* UNITS - Above medium-sized viewports
  ---------------------------------------*/
  
  .l-grid--divide-2  >  .grid_unit  { width: 50%; } 
  .l-grid--divide-3  >  .grid_unit  { width: 33.33333%; }
  .l-grid--divide-4  >  .grid_unit  { width: 25%; } 
  .l-grid--divide-5  >  .grid_unit  { width: 20%; } 
  .l-grid--divide-6  >  .grid_unit  { width: 16.66666%; }
  .l-grid--divide-7  >  .grid_unit  { width: 14.28571%; }
  .l-grid--divide-8  >  .grid_unit  { width: 12.5%; }



  /* SPATIALS - Above medium-sized viewports
  ---------------------------------------*/

  /* Spatial units in thirds */
  .l-grid--divide-3  >  .l-grid_unit--span-2  { width: 66.66666%; }

  /* Spatial units in fourths */
  .l-grid--divide-4  >  .l-grid_unit--span-2  { width: 50%; }
  .l-grid--divide-4  >  .l-grid_unit--span-3  { width: 75%; }

  /* Spatial units in fifths */
  .l-grid--divide-5  >  .l-grid_unit--span-2  { width: 40%; }
  .l-grid--divide-5  >  .l-grid_unit--span-3  { width: 60%; }
  .l-grid--divide-5  >  .l-grid_unit--span-4  { width: 80%; }

  /* Spatial units in sixths */
  .l-grid--divide-6  >  .l-grid_unit--span-2  { width: 33.33333%; }
  .l-grid--divide-6  >  .l-grid_unit--span-3  { width: 50%; }
  .l-grid--divide-6  >  .l-grid_unit--span-4  { width: 66.66666%; }
  .l-grid--divide-6  >  .l-grid_unit--span-5  { width: 83.33333%; }

  /* Spatial units in sevenths */
  .l-grid--divide-7  >  .l-grid_unit--span-2  { width: 28.57142%; }
  .l-grid--divide-7  >  .l-grid_unit--span-3  { width: 42.85714%; }
  .l-grid--divide-7  >  .l-grid_unit--span-4  { width: 57.14285%; }
  .l-grid--divide-7  >  .l-grid_unit--span-5  { width: 71.42857%; }
  .l-grid--divide-7  >  .l-grid_unit--span-6  { width: 85.71428%; }

  /* Spatial units in eights */
  .l-grid--divide-8  >  .l-grid_unit--span-2  { width: 25%; }
  .l-grid--divide-8  >  .l-grid_unit--span-3  { width: 37.5%; }
  .l-grid--divide-8  >  .l-grid_unit--span-4  { width: 50%; }
  .l-grid--divide-8  >  .l-grid_unit--span-5  { width: 62.5%; }
  .l-grid--divide-8  >  .l-grid_unit--span-6  { width: 75%; }
  .l-grid--divide-8  >  .l-grid_unit--span-7  { width: 87.5%; }

}








/* DEMO Styles
-----------------------------------------*/

.demo-page {
  margin: 2em auto;
  padding: 1.5em 1.5em 1px;
  max-width: 95em;
  width: 80%;
  background: #ddd;
  border-radius: 1em;
}


.box,
.box-alt,
.box-header,
.box-nested {
  background: orange;
  border-radius: 1em;
  margin:  0 0 2em;
  text-align: center;
  text-transform: uppercase;
  font-size: .75rem;
  line-height: 6rem;
}

.box-nested {
  margin-bottom: 0;
  background: #378567;
}

.box-alt {
  background: #4885c7;
}

.box-header {
  line-height: 4rem;
  background: #aaa;
}
              
            
!

JS

              
                /**
 * AkvaGrid lite
 *
 * Author: @robertpiira
 * Github: https://github.com/robertpiira/akvagrid-lite
 * Browser support: Chrome (more will follow)
 *
 */

var akvaGrids = [
  {
    gridName: 'desktop',
    breakpoints: {from: {size: 768, unit: 'px'}},
    columnCount: 6,
    gutterWidth: {size: 1, unit: 'em'},
    outerGutterWidth: {size: -1, unit: 'em'},
    borderTheme: {color: 'blue', style: 'solid'},
    width: {size: 80, unit: '%'},
    opacity: 0.5,
    zindex: '100'
  },
  {
    gridName: 'desktop-alt',
    breakpoints: {from: {size: 768, unit: 'px'}},
    columnCount: 4,
    gutterWidth: {size: 1, unit: 'em'},
    outerGutterWidth: {size: -1, unit: 'em'},
    borderTheme: {color: 'green', style: 'dashed'},
    width: {size: 80, unit: '%'},
    opacity: 0.5,
    zindex: '100'
  },
  {
    gridName: 'below-desktop',
    breakpoints: {to: {size: 767, unit: 'px'}},
    columnCount: 4,
    gutterWidth: {size: 1, unit: 'em'},
    outerGutterWidth: {size: -1, unit: 'em'},
    borderTheme: {color: 'green', style: 'solid'},
    width: {size: 80, unit: '%'},
    opacity: 0.5,
    zindex: '100'
  }
];

(function (grids, $) {

  'use strict';

  var debug = {
    grid: false,
    code: true
  };

  var els = {
    wrapper:    '.akva-grid',
    inner:      '.akva-inner',
    columns:    '.akva-cols',
    column:     '.akva-col',
    baseline:   '.akva-baseline',
    line:       '.akva-baseline-unit'
  };

  var common = {

    getPageHeight: function () {
      var pageHeight = $('html')[0].scrollHeight,
          windowHeight = $(window).height();
      return (pageHeight >= windowHeight) ? pageHeight : windowHeight;
    },

    // Throttle copyright (c) 2012, Nicholas C. Zakas
    throttle: function (method, scope) {
      clearTimeout(method._tId);
      method._tId = setTimeout(function () {
        method.call(scope);
      }, 700);
    },

    log: function () {
      if (debug.code) {
        if (window.console && window.console.log && window.console.log.apply) {
          window.console.log.apply(console, ['akva: ', arguments]);
        }
      }
    }

  };

  var Grid = function Grid(o) {
    this.gridName = o.gridName;
    this.columnCount = o.columnCount;
    this.breakpoints = (o.breakpoints) ? {from: (o.breakpoints.from) ? o.breakpoints.from.size + o.breakpoints.from.unit: null, to: (o.breakpoints.to) ? o.breakpoints.to.size + o.breakpoints.to.unit: null} : null;
    this.lineHeight = (o.lineHeight) ? ((o.lineHeight.size) ? o.lineHeight.size : null) + o.lineHeight.unit : null;
    this.gutterWidth = (o.gutterWidth) ? ((o.gutterWidth.size) ? o.gutterWidth.size : 0) + o.gutterWidth.unit : 0;
    this.outerGutterWidth = (o.outerGutterWidth) ? ((o.outerGutterWidth.size) ? o.outerGutterWidth.size : 0) + o.outerGutterWidth.unit : 0;
    this.width = (o.width) ? ((o.width.size) ? o.width.size : 'auto') + o.width.unit : null;
    this.borderTheme = (o.borderTheme) ? {color: o.borderTheme.color, style: o.borderTheme.style} : null;
    this.maxWidth = (o.maxWidth) ? ((o.maxWidth.size) ? o.maxWidth.size : 'auto') + o.maxWidth.unit : 'auto';
    this.opacity = (o.opacity) ? o.opacity : 1;
    this.zindex = (o.zindex) ? o.zindex : 1;

    // Handle visibility of grids with matchMedia
    var isVisible = true;
    var query;

    if (this.breakpoints) {

      query = {
        from: (this.breakpoints.from) ? '(min-width:' + this.breakpoints.from + ')' : '',
        and: (this.breakpoints.from && this.breakpoints.to) ? ' and ' : '',
        to: (this.breakpoints.to) ? '(max-width:' + this.breakpoints.to + ')' : '',
        id: o.gridName
      };

      var setVisibility = function (query) {
        isVisible = (query.matches) ?  true : false;
      };

      var handleWindowWidthChange = function (query, id) {
        if (query.matches) {
          $(els.wrapper + '-' + id).show();
        } else {
          $(els.wrapper + '-' + id).hide();
        }
      };

      (function addQueries() {
        var id  = query.id;
        var q   = query.from + query.and + query.to;
        var mq  = window.matchMedia(q);
        
        mq.addListener(function () {
          handleWindowWidthChange(mq, id);
        });

        setVisibility(mq);
        
      }());

      // On load visibility state
      this.isVisible = isVisible;
    }
    
  };

  Grid.prototype = {

    init: function () {

      common.log('Prototype init: ' + this.gridName + ' grid', this);

      var that = this;
      this.build();
      this.timer = null;
      this.updateGridOnWindowWidthChange();

      window.onresize = function () {
        common.throttle(that.updateGridOnWindowWidthChange, that);
      };

    },

    updateGridOnWindowWidthChange: function () {

      var that = this;
      var grids = $(els.wrapper);

      grids.each(function () {
        var thisGrid = $(this);
        if (thisGrid.is(':visible')) {
          thisGrid.css('height', common.getPageHeight());
          that.createBaseline(common.getPageHeight(), thisGrid);
        }
      });

    },

    build: function () {
      var wrapper   = this.createWrapper();
      var columns   = this.createColumns();
      var baseline  = this.createBaseline(common.getPageHeight());

      wrapper.find(els.inner).append(columns).append(baseline);

      $('body').append(wrapper);
    },

    createWrapper: function () {
      var wrapper = $('<div class="' + els.wrapper.slice(1) + '" />').css({
        maxWidth: this.maxWidth,
        width: this.width,
        opacity: this.opacity,
        zIndex: this.zindex
      }).addClass('akva-grid-' + this.gridName);
      
      var inner = $('<div class="' + els.inner.slice(1) + '" />');

      if (this.outerGutterWidth) {
        inner.css({
          'margin-left': this.outerGutterWidth,
          'margin-right': this.outerGutterWidth
        });
      }

      if (!this.isVisible) {
        wrapper.hide();
      }

      wrapper.append(inner);

      return wrapper;
      
    },

    createColumns: function () {
      common.log('creating ' + this.columnCount + ' columns for ' + this.gridName);
      var columns = $('<div class="' + els.columns.slice(1) + '" />');
      var column = $('<div class="' + els.column.slice(1) + '" />');
      var columnClone;
      var i = 0;

      // Border theme
      if (this.borderTheme) {
        column.css({
          borderColor: this.borderTheme.color,
          borderStyle: this.borderTheme.style
        });
      }

      // Gutters
      column.css({
        margin: '0 ' + this.gutterWidth
      });

      for (; i < this.columnCount; i++) {
        columnClone = column.clone();
        columns.append(columnClone);
      }

      return columns;

    },

    createBaseline: function (pageHeight, target) {

      if (!this.lineHeight) {
        return false;
      }

      var wrapper = (target !== undefined) ? target.find(els.baseline) : $('<div class="' + els.baseline.slice(1) + '" />');
      var line = $('<div class="' + els.line.slice(1) + '" />');
      var htmlLine;
      var markup = "";
      var lineCount = 0;

      if (this.lineHeight) {
        line.css({
          height: this.lineHeight
        });
      }

      lineCount = Math.ceil((pageHeight / line.height()) + 10);
      htmlLine = $('<div>').append(line.clone().remove()).html();

      // Max line elements
      if (lineCount > 1000) {
        lineCount = 1000;
      }

      // Trash the old lines
      wrapper.empty();

      // Create new lines
      while (lineCount--) {
        markup += htmlLine;
      }

      wrapper.html(markup);

      return wrapper;

    }

  };

  var akva = {

    instances: [],

    init: function () {

      this.addGrids(grids);
      this.style();
      this.initGrids();

    },

    addGrids: function (grids) {
      var that = this;

      $.each(grids, function (i) {
        var o = new Grid(grids[i]);
        that.instances.push(o);
      });
    },

    initGrids: function () {
      $.each(this.instances, function (i, o) {
        o.init();
      });
    },

    style: function () {
    
      var styles = '\
        .akva-grid,\
        .akva-grid * {\
          margin: 0;\
          padding: 0;\
          box-sizing: border-box;\
          pointer-events:none;\
        }\
        .akva-baseline {\
          position: absolute;\
          top: 0;\
          left: 0;\
          width: 100%;\
          height: 100%;\
          overflow: hidden;\
        }\
        .akva-baseline-unit {\
          height: 1.5em;\
          border-bottom: 1px dashed rgba(63, 95, 110, .5);\
        }\
        .akva-grid {\
          position: absolute;\
          left: 0;\
          right: 0;\
          top: 0;\
          bottom: 0;\
          margin: 0 auto;\
          z-index: 1;\
        }\
        .akva-inner {\
          height: 100%\
        }\
        .akva-cols {\
          height: 100%;\
          display: -webkit-flex;\
          display: flex;\
        }\
        .akva-col {\
          -webkit-flex: 1;\
          flex: 1;\
          border: 1px solid rgba(110, 180, 235,.9);\
          border-width: 0 1px;\
        }\
        ';
    
      this.addCSS(styles);

    },
      
    addCSS: function (css) {
      
      var styleElement = $('<style />', {
        type: 'text/css'
      });

      if (styleElement.styleSheet) {
        styleElement.styleSheet.cssText = css;
      } else {
        styleElement.append(document.createTextNode(css));
      }
      
      $('head').append(styleElement);

    }

  };

  akva.detect = function () {
    if (true) {
      akva.init();
    }
  }();

}(akvaGrids, jQuery));
              
            
!
999px

Console