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

              
                <div class="wrap">

  <div row>
    <div class="box_1">Box 1</div>
    <div class="box_2">Box 2</div>
    <div class="box_3">Box 3</div>
    <div class="box_4">Box 4</div>
    <div class="box_1">Box 1a</div>
    <div class="box_2">Box 2a</div>
    <div class="box_3">Box 3a</div>
    <div class="box_4">Box 4a</div>
  </div>
  
</div>
              
            
!

CSS

              
                /* In this pane: First mixins, then implementation */

// Global variables:
// Specify a gutter and padding amount using any CSS units you'd like
// if unitless, interpreted as pixels (e.g., $_fg_gutter: 24 !default;)
$_fg_gutter: 24px !default; // gutter between columns. Set as desired.
$_fg_padding: 12px !default; // padding for column boxes. Set as desired, can override for individual columns.



// *** Main mixin to create a per-row layout *** //
@mixin _fg($colList, $gutter: $_fg_gutter, $padding: $_fg_padding) {
  // If gutter/padding is unitless, give it px units:
  @if unitless($gutter) {
    $gutter: $gutter * 1px;
  }
  @if unitless($padding) {
    $padding: $padding * 1px;
  }

  @if type-of($colList) == number { // call _fg_grid() directly
    @include _fg_grid($colList, $gutter, $padding);
  } @else if type-of($colList) == list and length($colList) > 1 {
    // Count how many columns there are altogether
    $columnCount: 0;
    @each $i in $colList {
      $columnCount: $columnCount + $i;
    }

    @include _fg_grid($columnCount, $gutter, $padding);

    @for $i from 1 through length($colList) { // set child items widths using nth:child()
      $c: nth($colList, $i);
      & > :nth-child(#{length($colList)}n+#{$i}) {
        @include _fg_width($c/$columnCount, $gutter);
      }
    }
  }
}


// *** Set up grid with equal width columns *** //
@mixin _fg_grid($cols: 0, $gutter: $_fg_gutter, $padding: $_fg_padding) {
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    margin-left: (-1 * $gutter);

  > * {
    @if $padding != 0 {
      padding: $padding;
    }
    margin-left: $gutter;
    box-sizing: border-box;
  }

  $calc_percent: (1/$cols) * 100%;

  > * { width: calc(#{$calc_percent} - #{$gutter}); }
}


// *** width override for a column *** //
@mixin _fg_width($ratio, $gutter: $_fg_gutter) {
  @if unitless($gutter) {
    $gutter: $gutter * 1px;
  }

  $calc_percent: $ratio * 100%;
  width: calc(#{$calc_percent} - #{$gutter});
};

/*----------->>Breakpoints>>---------------*/
// Override as required.
$_fg_small: 768px !default; // up to "tablet" size
$_fg_medium: 1024px !default; // up to "desktop" size
$_fg_large: 1280px !default; // up to bigger desktop size

@mixin _fg_breakpoint($_fg_media) {
  $small: $_fg_small;
  $medium: $_fg_medium;
  $large: $_fg_large;
  
  @if unitless($_fg_small) {
    $small: $_fg_small * 1px;
  }
  @if unitless($_fg_medium) {
    $medium: $_fg_medium * 1px;
  }
  @if unitless($_fg_large) {
    $large: $_fg_large * 1px;
  }

  @if $_fg_media == small {
    @media only screen and (min-width: $small) { @content; }
  }
  @else if $_fg_media == medium {
    @media only screen and (min-width: $medium) { @content; }
  }
  @else if $_fg_media == large {
    @media only screen and (min-width: $large) { @content; }
  }

  @else if type-of($_fg_media) == number {
    @if unitless($_fg_media) {
      $_fg_media: $_fg_media * 1px;
    }
    @media only screen and (min-width: $_fg_media) { @content; }
  }
}


// *** Implementation and overrides *** //

// Container:
[row] {
  @include _fg(2, 60, 0); // 50/50, custom gutter of 60px, custom padding of 0px
  @include _fg_breakpoint(medium) { @include _fg(2 2 1 1); }
  
  > div { margin-bottom: 15px; }
}

// Override styles for individual boxes:
// First a wrapper to constrain o'all width:
.wrap { max-width: 1024px; margin: 0 auto; background: #e4e4e4; }

.box_1 {
  background-color: red;
  @include _fg_breakpoint(medium) { background-color: gray;};
}

.box_2 {
  background-color: green;
  border: 5px solid orange; // yes, borders are OK
}

.box_3 {
  background-color: blue;
}

.box_4 {
  background-color: yellow;
}
              
            
!

JS

              
                // Just to display the width of each box on initial load:
$('[row] > *').each(function() {
  $(this).append(' - Width:' + $(this).width());
});
              
            
!
999px

Console