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 class='title'>Flexbox Rules!</h1>
<div class='container'>
  <div class='thing'>Yay!</div>
  <div class='thing'>Flexbox 4evr!</div>
  <div class='thing'><span class="emoji">๐Ÿ™€</span></div>
  <div class='thing'>Easy!</div>
  <div class='thing'><span class="emoji">๐Ÿ‘</span></div>
  <div class='thing'>1 of ur 5 a day!<span class="emoji">๐Ÿ“</span></div>
  <div class='thing'><span class="emoji">๐Ÿš€</span></div>
  <div class='thing'>Super good!</div>
  <div class='thing'>Gives You Health!<span class="emoji">๐Ÿ’•</span></div>
  <div class='thing'><span class="emoji">๐Ÿ”ฅ</span></div>
  <div class='thing'>Delicious!<span class="emoji">๐ŸŒญ</span></div>
  <div class='thing'>Win!!<span class="emoji">๐Ÿ…</span></div>
  <div class='thing'>Life Changing!</div>
  <div class='thing'>U won't believe wot hapened next...</div>
</div>
              
            
!

CSS

              
                /** 
* Make flexbox grids super easy!
* ---
* @param $cols โ€Šโ€” โ€ŠNumber of columns
* @param $marginโ€Š โ€” โ€ŠMargin with unit
*/

@mixin flexgrid($cols, $margin) {
  $width: (100% / $cols);
  $calc-margin: (($margin * $cols) - $margin) / $cols;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  &:after {
    flex: auto;
    margin: 0 auto;
    content: "";
  }
  >* {
    width: calc( #{$width} - #{$calc-margin} );
    margin-left: $margin / 2;
    margin-right: $margin/ 2;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(#{$cols}n) {
      margin-right: 0;
    }
    &:nth-child(#{$cols}n + 1) {
      margin-left: 0;
    }
  }
}

.flexgrid { // Namespace for Demo
  .container {
    @media screen and (min-width: 600px) and (max-width: 799px) {
      @include flexgrid(2, 1rem);
    }
    @media screen and (min-width: 800px) and (max-width: 999px) {
      @include flexgrid(3, 1rem);
    }
    @media screen and (min-width: 1000px) {
      @include flexgrid(4, 1rem);
    }
  }
}























































/* 
* Demo Styles
*/
.flexgrid {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "liga", "kern";
  overflow-y: scroll;
  overflow-x: hidden;
  width: 100%;
  *, *:before, *:after {
    box-sizing: border-box;
  }
  body {
    min-height: 100vh;
    font-family: 'Baloo Tamma', cursive;
    text-align: center;
    text-transform: uppercase;
    line-height: 1;
    overflow: hidden;
  }

  .container {
    padding: 0 1rem;
  }

  .title {
    font-family: 'Baloo Tamma', cursive;
    font-size: 300%;
    padding: 2rem 1rem;
  }

  .thing {
    color: #FEFEFE;
    font-size: 200%;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    margin-bottom: 1rem;
    cursor: pointer;
    box-shadow: 0 2.5px 5px rgba(25, 25, 25, 0.1);
    background: #1dd2af;
    background: linear-gradient(to bottom, #1dd2af, #17a689);
    &:hover {
      animation-name: shake;
      animation-duration: 1s;
      animation-iteration-count: infinite;
    }
    &:nth-child(1), 
    &:nth-child(4), 
    &:nth-child(7),
    &:nth-child(10) {
      background: #fed26a;
      background: linear-gradient(to bottom, #fed26a, #fec238);
      &:hover {
        animation-name: bounce;
      }
    }
    &:nth-child(2), 
    &:nth-child(5), 
    &:nth-child(9),
    &:nth-child(14) {
      background: #7ad0ff;
      background: linear-gradient(to bottom, #7ad0ff, #47beff);
      &:hover {
        animation-name: swing;
      }
    }
    &:nth-child(3), 
    &:nth-child(6), 
    &:nth-child(12) {
      background: #df6974;
      background: linear-gradient(to bottom, #df6974, #d73f4e);
      &:hover {
        animation-name: tada;
      }
    }
  }

  .emoji {
    font-size: 200%;
    transform: translateY(20%);
  }

  @keyframes bounce {
    from, 20%, 53%, 80%, to {
      animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
      transform: translate3d(0,0,0);
    }

    40%, 43% {
      animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
      transform: translate3d(0, -30px, 0);
    }

    70% {
      animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
      transform: translate3d(0, -15px, 0);
    }

    90% {
      transform: translate3d(0,-4px,0);
    }
  }


  @keyframes shake {
    from, to {
      transform: translate3d(0, 0, 0);
    }

    10%, 30%, 50%, 70%, 90% {
      transform: translate3d(-10px, 0, 0);
    }

    20%, 40%, 60%, 80% {
      transform: translate3d(10px, 0, 0);
    }
  }

  .shake {
    animation-name: shake;
  }


  @keyframes swing {
    20% {
      transform: rotate3d(0, 0, 1, 15deg);
    }

    40% {
      transform: rotate3d(0, 0, 1, -10deg);
    }

    60% {
      transform: rotate3d(0, 0, 1, 5deg);
    }

    80% {
      transform: rotate3d(0, 0, 1, -5deg);
    }

    to {
      transform: rotate3d(0, 0, 1, 0deg);
    }
  }


  @keyframes tada {
    from {
      transform: scale3d(1, 1, 1);
    }

    10%, 20% {
      transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
    }

    30%, 50%, 70%, 90% {
      transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
    }

    40%, 60%, 80% {
      transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
    }

    to {
      transform: scale3d(1, 1, 1);
    }
  }
}
              
            
!

JS

              
                // Styled components version, not needed if using scss

/** 
* Make flexbox grids super easy!
* ---
* @param columnsโ€Š โ€” โ€ŠNumber of columns
* @param margin โ€Šโ€” โ€ŠMargin with unit
*/

const flexGrid = ({ columns, margin }) => {
  const width = `${100 / columns}%`;
  const unitlessMargin = margin.match(/[\d?.]/g).join('');
  const unit = margin.match(/[a-zA-Z%]+/g).join('');
  const calcMargin = ((unitlessMargin * columns) - unitlessMargin) / columns;
  return (`
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    &:after {
      flex: auto;
      margin: 0 auto;
      content: "";
    }
    >* {
      width: calc(${width} - ${calcMargin});
      margin-left: ${unitlessMargin / 2}${unit};
      margin-right: ${unitlessMargin / 2}${unit};
      &:nth-child(1) {
        margin-left: 0;
      }
      &:nth-child(${columns}n) {
        margin-right: 0;
      }
      &:nth-child(${columns}n + 1) {
        margin-left: 0;
      }
    }
  `)
}
              
            
!
999px

Console