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

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

              
                .demo

  h1 Simple Flexbox Grid System
  
  p I'm gonna go build my own grid system! <em><a href="https://www.youtube.com/watch?v=BGi6Q1pNbS0">With blackjack. And hookers.</a></em>

  h2 The Basics
  
  p The grid is divided into 12 units.

  ul
    li Add <code>.has-columns</code> to the container/wrapper/row
    li Add <code>.column.</code> and <code>.column-<em>{size}</em></code> to each column. The value for <code>{size}</code> is the number of units the column should take it.
    
  p Gutters are added in between 2 adjacent columns

  .has-columns
    .column.column-12
      | .column-12

  .has-columns
    .column.column-6
      | .column-6
    .column.column-6
      | .column-6

  .has-columns
    .column.column-4
      | .column-4
    .column.column-4
      | .column-4
    .column.column-4
      | .column-4

  .has-columns
    .column.column-3
      | .column-3
    .column.column-3
      | .column-3
    .column.column-3
      | .column-3
    .column.column-3
      | .column-3

  .has-columns
    .column.column-2
      | .column-2
    .column.column-2
      | .column-2
    .column.column-2
      | .column-2
    .column.column-2
      | .column-2
    .column.column-2
      | .column-2
    .column.column-2
      | .column-2

  h2 Combining Columns
  
  p It's possible to mix columns of different widths. As long as their combined number of units does not exceed the total number of units (e.g. 12). They will fit into their row.

  .has-columns
    .column.column-2
      | .column-2
    .column.column-4
      | .column-4
    .column.column-4
      | .column-4
    .column.column-2
      | .column-2

  .has-columns
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-1
      | .column-1
    .column.column-5
      | .column-5

  .has-columns
    .column.column-1
      | .column-1
    .column.column-4
      | .column-4
    .column.column-5
      | .column-5
    .column.column-2
      | .column-2

  h2 Responsive Columns
  
  p Different viewport sizes are defined.
  
  ul
    li <strong>xxs</strong> = <code>20em</code> <em>(<code>320px</code>)</em>
    li <strong>xs</strong> = <code>30em</code> <em>(<code>480px</code>)</em>
    li <strong>sm</strong> = <code>48em</code> <em>(<code>768px</code>)</em>
    li <strong>md</strong> = <code>64em</code> <em>(<code>1024px</code>)</em>
    li <strong>lg</strong> = <code>75em</code> <em>(<code>1200px</code>)</em>
    li <strong>xl</strong> = <code>90em</code> <em>(<code>1440px</code>)</em>
    
  p It's possible to add classes to the columns which only target a given size for a given viewportsize in the format of <code>.column-<em>{viewportsize}</em>-<em>{size}</em></code>. The value for <code>{viewportsize}</code> is one of the defined viewport sizes. The value for <code>{size}</code> is the number of units the column should take (for the given <code>{viewportsize}</code>).
  p E.g. a column with the class <code>.column-md-4</code> will be 4 units wide for the <code>md</code> viewport size ranging from <code>64em</code> to <code>75em</code>.
  
  p You can combine several classes of different sizes. E.g. a column with the class <code>.column-md-6.column-lg-4</code> will be 6 units wide for the <code>md</code> viewport size, and 4 units wide for the <code>lg</code> viewport size.

  .has-columns
    .column.column-sm-6.column-md-4
      | .column-sm-6.column-md-4
    .column.column-sm-6.column-md-4
      | .column-sm-6.column-md-4

  h2 Offsetting Columns
  
  p It's possible to offsets columns by adding <code>.offset-{size}</code> and <code>.offset-{viewportsize}-{size}</code> classes.

  .has-columns
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1

  .has-columns
    .column.column-md-12
      | .column-md-12
          
  .has-columns
    .column.column-sm-11.offset-sm-1
      | .column.column-sm-11.offset-sm-1
          
  .has-columns
    .column.column-sm-10.offset-sm-2
      | .column.column-sm-10.offset-sm-2
          
  .has-columns
    .column.column-sm-9.offset-sm-3
      | .column.column-sm-9.offset-sm-3
          
  .has-columns
    .column.column-sm-8.offset-sm-4
      | .column.column-sm-8.offset-sm-4
          
  .has-columns
    .column.column-sm-7.offset-sm-5
      | .column.column-sm-7.offset-sm-5
          
  .has-columns
    .column.column-sm-6.offset-sm-6
      | .column.column-sm-6.offset-sm-6
          
  .has-columns
    .column.column-sm-5.offset-sm-7
      | .column.column-sm-5.offset-sm-7
          
  .has-columns
    .column.column-sm-4.offset-sm-8
      | .column.column-sm-4.offset-sm-8

  .has-columns
    .column.offset-md-6.column-md-6
      | .column-md-6.offset-md-6

  .has-columns
    .column.offset-md-4.column-md-4
      | .column-md-4.offset-md-4

  .has-columns
    .column.column-xs-12.column-sm-10.offset-sm-1.column-md-8.offset-md-2
      | .column-xs-12.column-sm-10.offset-sm-1.column-md-8.offset-md-2

  .has-columns
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
      
  h2 Mixing Offsets
  
  p Offsets can be mixed and be different per viewport size.

  .has-columns
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1

  .has-columns
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1.offset-sm-10
      | .column-sm-1.offset-sm-10


  .has-columns
    .column.column-md-2.offset-md-2
      | .column-md-2.offset-md-2
    .column.column-md-2.offset-md-2
      | .column-md-2.offset-md-2
    .column.column-md-2.offset-md-2
      | .column-md-2.offset-md-2

  .has-columns
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1
    .column.column-sm-1.offset-sm-1
      | .column-sm-1.offset-sm-1

  .has-columns
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1
    .column.column-sm-1
      | .column-sm-1

  .has-columns
    .column.column-xs-6.column-md-5.offset-md-1.offset-lg-0.column-lg-4
      | .column-xs-6.column-md-5.offset-md-1.offset-lg-0.column-lg-4
    .column.column-xs-6.column-md-5.column-lg-4
      | .column-xs-6.column-md-5.column-lg-4
    .column.column-xs-6.column-md-5.column-lg-4
      | .column-xs-6.column-md-5.column-lg-4

  .has-columns
    .column.column-xs-1
      | .column-xs-1
    .column.column-xs-1.offset-xs-1
      | .column-xs-1.offset-xs-1
    .column.column-xs-1.offset-xs-2
      | .column-sxs-1.offset-xs-2
    .column.column-xs-1.offset-xs-1
      | .column-xs-1.offset-xs-1
    .column.column-xs-1.offset-xs-1
      | .column-xs-1.offset-xs-1
    .column.column-xs-1.offset-xs-1
      | .column-xs-1.offset-xs-1
      
  h2 Nesting Columns
  
  p The nesting of columns is supported, by putting a new <code>.has-columns</code> into a <code>.column</code>
          
  .has-columns
    .column.column-sm-6
      | .column-sm-6
      .has-columns
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
    .column.column-sm-6
      | .column-sm-6
      .has-columns
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
        .column.column-xs-2
          | .column-xs-2
          
  .has-columns
    .column.column-lg-10.offset-lg-1
      | .column-lg-10.offset-lg-1
      .has-columns
        .column.column-sm-6
          | .column-sm-6
        .column.column-sm-6
          | .column-sm-6
          
  .has-columns
    .column.column-sm-10.offset-sm-1
      | .column-sm-10.offset-sm-1
      .has-columns
        .column.column-xs-6
          | .column-xs-6
          .has-columns
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
        .column.column-xs-6
          | .column-xs-6
          .has-columns
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
            .column.column-xs-2
              | .column-xs-2
  
  h2 Auto and Stretch Columns
  
  p In some cases one would want to implement a column based UI, but without sticking to the grid. Think of a message component that holds an avatar and a content. In that case the avatar should only take up the space it requires, and the content should take up the remaining space.
  
  ul
    li <code>.column-auto</code> columns will not take up a given portion, but will only take up the space their content requires.
    li <code>.column-stretch</code> columns will take up the remaining space.

  .has-columns
    .column.column-auto
      | .column-auto
    .column.column-stretch
      | .column-stretch
    .column.column-auto
      | .column-auto
      
              
            
!

CSS

              
                // Simple Flexbox Grid System
// Built by @bramus – https://www.bram.us/

// See https://www.bram.us/2016/10/07/simple-flexbox-grid-system/ for more details.

$num-columns = 12
$gutter = 1em
$sizes = {
  'xxs': 20, // 320px
  'xs': 30, // 480px
  'sm': 48, // 768px
  'md': 64, // 1024px
  'lg': 75, // 1200px
  'xl': 90, // 1440px
}
    
.has-columns
  width 100%
  display flex
  flex-direction row
  flex-wrap wrap
  justify-content flex-start
  align-items stretch
  box-sizing border-box
  
  .column
    margin auto
    overflow hidden
    flex 0 0 100%
    box-sizing border-box
    margin 0 $gutter 0 0
        
    &:last-child
      margin-right 0
      
    for $i in 0..$num-columns
      
      $percentage = unit(($i / $num-columns) * 100, '%')
      $adjustedgutter = $gutter * (1 - ($i / $num-columns))
      $adjustedoffset = ($gutter * (1 - (($num-columns - $i) / $num-columns)))
      
      &.column-{$i}
        flex-basis "calc(%s - %s)" % ($percentage $adjustedgutter)
        
      &.offset-{$i}
        margin-left "calc(%s + %s)" % ($percentage $adjustedoffset)
    
    for $name, $size in $sizes

      // Make sure that the smallest size also applies to the range 0 - $size
      // if ($name == keys($sizes)[0]) {
      //  $size = 0
      //}

      @media (min-width: unit($size, 'em'))
        for $i in 0..$num-columns

          $percentage = unit(($i / $num-columns) * 100, '%')
          $adjustedgutter = $gutter * (1 - ($i / $num-columns))
          $adjustedoffset = ($gutter * (1 - (($num-columns - $i) / $num-columns)))

          &.column-{$name}-{$i}
            flex-basis "calc(%s - %s)" % ($percentage $adjustedgutter)
          &.offset-{$name}-{$i}
            margin-left "calc(%s + %s)" % ($percentage $adjustedoffset)

    &.column-auto
      flex-basis auto
    &.column-stretch
      flex 1 1 auto

// extra demo styles, to visualize everything
code
  background #EFEFEF
  padding 0 0.2em
  color #000

.demo
  width 80%
  margin 0 auto
  
  > .has-columns
    margin-bottom 1em
    
  .has-columns
    background rgba(255,0,0,0.3)
  
    position relative

    &::after
       content ''
       position absolute
       left 50%
       width 2px
       margin-left -1px
       top -0.5em
       bottom -0.5em
       background red
       z-index -1
    
    .column
      background rgba(0,0,0,0.3)
      min-height 3em
      position relative
    
      &::after
         content ''
         position absolute
         left 50%
         width 2px
         margin-left -1px
         top 0
         bottom 0
         background green
         z-index -1
              
            
!

JS

              
                
              
            
!
999px

Console