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 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.

Quick-add: + add another resource

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.

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.

            
              <h2>2 columns</h2>
<div class="grid__col--2">
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
</div>

<h2>3 columns</h2>
<div class="grid__col--3">
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
</div>

<h2>4 columns</h2>
<div class="grid__col--4">
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
</div>

<h2>5 columns</h2>
<div class="grid__col--5">
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
</div>

<h2>6 columns</h2>
<div class="grid__col--6">
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
  <div class="col">
    <h3>H3 title</h3>
    <p>In platea urna, turpis in. Porttitor dictumst. Massa elementum habitasse eros cursus, nunc, natoque porta mus pellentesque, proin tortor, integer lundium ac mauris integer risus, a non elit nunc lundium, quis dapibus risus et! Porta, mus etiam, lorem
      nascetur nec urna penatibus placerat.</p>
  </div>
</div>
            
          
!
            
              // Base font size
$font-size-base: 16px;

// Global breakpoint variables (customisable)
$bp-xl: 1200px;
$bp-l: 960px;
$bp-m: 840px;
$bp-s: 640px;
$bp-xs: 480px;

// Min-width breakpoint
@mixin break-point-min($bp, $min-max: min-width) {
  $em: $bp/$font-size-base;
  @media(#{$min-max}: #{$em}em) { @content; }
}
// Max-width breakkpoint
@mixin break-point-max($bp, $min-max: max-width) {
  $em: $bp/$font-size-base;
  @media(#{$min-max}: #{$em}em) { @content; }
}

// Convert px to em function
@function pxToEm ($values, $elFontSize: $baseFontSize) {
  $list: ();

  @each $value in $values {
    @if ($value == 0 or $value == auto) {
      $list: append($list, $value);
    } @else {
      $emValue: ($value/$elFontSize)+em;
      $list: append($list, $emValue);
    }
  }
  @return $list;
}

// Styling of the h3 and p for the purpose of this demo
h3 {
  padding: pxToEm(0 15px, $font-size-base);
}
p {
  padding: pxToEm(0 20px, $font-size-base);
}

// Clearfix mixin
@mixin clearfix-me($method: $clearfix-method) {
  @if $method != overflow and $method != facebook and $method != micro and $method != stubborn {
    @warn "The clearfix method #{$method} is unkown";
    @extend %clearfix-micro;
  } @else {
    @extend %clearfix-#{$method};
  }

}

// Clearfix placeholder
%clearfix-micro {
  zoom: 1;
  &:before,
  &:after {
    content: " ";
    display: table;
  }
  &:after {
    clear: both;
  }
}


// GRID COLUMN CALCULATION
///////////////////////////

@function calculate-width ($col-span) {

    // Get the correct gutter calculation first ie...
    // -----------------------------------------------
    // 2 column = 1 gutter
    // 3 column = 2 gutters
    // etc...

    // Always one less gutter than the number of columns...
    $gutter-calc: ($col-span * $col-gutter) - $col-gutter; 

        // Now return the correctly calculated column width...
        @return (100% - $gutter-calc) / $col-span;
}


// GRID VARIABLES
//////////////////

$col-gutter: 1.6%; // If you increase the gutter size, the column widths will adjust accordingly.

$col-width-2: calculate-width(2);
$col-width-3: calculate-width(3);
$col-width-4: calculate-width(4);
$col-width-5: calculate-width(5);
$col-width-6: calculate-width(6);


// GRID MIXINS
///////////////

// Using a mixin instead, as a placeholder @extend call can't be used within a @media call

// Set / reset the columns
@mixin col-reset ($col-clear: none, $col-gutter-set: $col-gutter) {
    clear: $col-clear;
    margin-left: $col-gutter-set;
}

// Clear the first column (in each row) for each grid layout
@mixin col-clear ($col-clear: left, $col-gutter-remove: 0) {
    clear: $col-clear;
    margin-left: $col-gutter-remove;
}

// GRID IMPLEMENTATION
///////////////////////

// Base grid styles
/////////////////////////////////
[class^="grid__"],
[class*=" grid__"] {
  @include clearfix-me(micro);
  list-style: none; // In case a list is used
  padding: 0;
  margin: 0;

  .col {
    background-color: #000; // Demonstration purposes
    color: #fff; // Demonstration purposes
    float: left;
    margin: 0 0 pxToEm(15px, $font-size-base) $col-gutter;
    transition: all 0.2s linear;

        // Makes sure no gutter on single column layout (linear)
        @include break-point-max($bp-xs) {
            margin-left: 0;
        }

    // Remove margin-bottom from nested grid column
    .col {
        margin-bottom: 0;
    }

  }
}
/////////////////////////////////


// Grids with 2-6 columns share these rules
// More can be added eg. ".grid__col--7" etc.
.grid__col--2,
.grid__col--3,
.grid__col--4,
.grid__col--5,
.grid__col--6 {
    > .col {
        @include break-point-min($bp-xs) {

            width: $col-width-2;
            
            &:nth-child(n) {
                @include col-reset;
            }
            &:nth-child(2n+1) {
                @include col-clear;
            }
        }
    }
}

// Grids with 3-6 columns share these rules
.grid__col--3,
.grid__col--4,
.grid__col--5,
.grid__col--6 {
    > .col {
        @include break-point-min($bp-s) {

            width: $col-width-3;

            &:nth-child(n) {
                @include col-reset;
            }
            &:nth-child(3n+1), {
                @include col-clear;
            }
        }
    }
}

// Grids with 4-6 columns share these rules
.grid__col--4,
.grid__col--5,
.grid__col--6 {
    > .col {
        @include break-point-min($bp-m) {

            width: $col-width-4;

            &:nth-child(n) {
                @include col-reset;
            }
            &:nth-child(4n+1) {
                @include col-clear;
            }
        }
    }
}

// Grids with 5-6 columns share these rules
.grid__col--5,
.grid__col--6 {
    > .col {
        @include break-point-min($bp-l) {

            width: $col-width-5;

            &:nth-child(n) {
                @include col-reset;
            }
            &:nth-child(5n+1) {
                @include col-clear;
            }
        }
    }
}

// Grids with 6 columns
.grid__col--6 {
    > .col {
        @include break-point-min($bp-xl) {

            width: $col-width-6;

            &:nth-child(n) {
                @include col-reset;
            }
            &:nth-child(6n+1) {
                @include col-clear;
            }
        }
    }
}

// And so on......


/////////////////////////////////////////////////////////////
            
          
!
            
              // Nothing here at the moment.

// May extend the grid to handle equal heights content using flexbox with a flexbox polyfill for legacy browsers.
            
          
!
999px
Loading ..................

Console