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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h2>With last row complete</h2>
<div class="grid">
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
</div>

<h2>With last row missing one cell</h2>
<div class="grid">
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
</div>

<h2>With last row missing two cells in 3-column layout</h2>
<div class="grid">
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
  <div class="grid__cell"></div>
</div>
            
          
!
            
              //////////////////////////////////////////
// grid
// Breaks into 1-3 column grid depending on
// the breakpoint and automatically wraps
// items and aligns the last row
//////////////////////////////////////////
//
// Use:
// .grid
//   .grid__cell (as many as needed)

$screen-sm-min: 768px;
$screen-sm-max: 991px;
$screen-md-min: 992px;
$col-gap: 16px;

.grid__cell {
  margin-bottom: $col-gap;
  min-width: 0;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;

  &:last-of-type {
    margin-bottom: 0;
  }
}

@media (min-width: $screen-sm-min) {
  .grid {
    display: -ms-flexbox;
    display: flex;
    flex-wrap: wrap;

    // Creates a fake item that will push against
    // real items in the last row
    // This is used to align the column gaps into a nice grid
    // No height allows it to collapse when last row is complete
    &:after {
      content: '';
      display: block;
      -ms-flex: 1 1 auto;
      flex: 1 1 auto;
    }
  }
}

@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
  $width: calc(50% - #{$col-gap});

  .grid:after {
    width: $width;
  }

  .grid__cell {
    margin-right: $col-gap;
    width: $width;

    // Remove margin in last column
    &:nth-of-type(2n) {
      margin-right: 0;
    }

    // For when the last row is complete
    // . .
    // * .
    &:nth-of-type(2n-1):nth-last-of-type(2) {
      margin-bottom: 0;
    }
  }
}

@media (min-width: $screen-md-min) {
  $width: calc(33% - #{$col-gap});

  .grid:after {
    width: $width;
  }

  .grid__cell {
    margin-right: $col-gap;
    width: $width;

    // Remove margin in last column
    &:nth-of-type(3n) {
      margin-right: 0;
    }

    // For when there two items in the last row
    // . . .
    // * .
    &:nth-of-type(3n-2):nth-last-of-type(2) {
      margin-bottom: 0;
    }

    // For when the last row is complete
    // . . .
    // * * .
    &:nth-of-type(3n-1):nth-last-of-type(2),
    &:nth-of-type(3n-2):nth-last-of-type(3) {
      margin-bottom: 0;
    }

    // When there is only one item in the last rpw
    // Fill the margin so it's like the last item is
    // double the width
    // . . .
    // *->
    &:nth-of-type(3n-2):last-of-type {
      margin-right: calc(33% + #{$col-gap * 2});
    }
  }
}


//////////////////////////////////
// Styles for the demo enviorment
//////////////////////////////////

html {
  box-sizing: border-box;
  font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
}

*, *::before, *::after {
  box-sizing: inherit;
}

h2 {
  margin-top: 2rem;
  margin-bottom: .5rem;
}

.grid {
  margin-bottom: 3rem;
}

.grid__cell {
  background-color: #ff8a00;
  color: #fff;
  text-align: center;
  min-height: 100px;
  box-shadow: 0 .15em .15em rgba(0,0,0,.18),0 .75em .8em rgba(0,0,0,.16);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console