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.

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

            
              <h1>Absolute</h1>

<div class="absolute-test">
  <div class="relative test-1">
    <div class="absolute">@include absolute(0)</div>  
  </div>

  <div class="relative test-2">
    <div class="absolute">@include absolute(20px 0)</div>  
  </div>

  <div class="relative test-3">
    <div class="absolute">@include absolute(0 0 x auto)</div>  
  </div>
</div> <!-- /absolute-test -->


<h1>Relative</h1>

<div class="relative-test">
  <div class="relative test-1">
    <div class="relative">@include relative(-10px)</div>  
  </div>

  <div class="relative test-2">
    <div class="relative">@include relative(10px x x x)</div>  
  </div>

  <div class="relative test-3">
    <div class="relative">@include relative(x x -20px 50%)</div>  
  </div>
</div> <!-- /relative-test -->


<h1>Padding</h1>

<div class="padding-test">
  <div class="relative test-1">
    <div class="padding">@include padding(10px)</div>  
  </div>

  <div class="relative test-2">
    <div class="padding">@include padding(10px x x x)</div>  
  </div>

  <div class="relative test-3">
    <div class="padding">@include padding(x x 20px 50%)</div>  
  </div>
</div> <!-- /padding-test -->


<h1>Margin</h1>

<div class="margin-test">
  <div class="relative test-1">
    <div class="margin">@include margin(10px)</div>  
  </div>

  <div class="relative test-2">
    <div class="margin">@include margin(10px x x x)</div>  
  </div>

  <div class="relative test-3">
    <div class="margin">@include margin(x x 20px 50%)</div>  
  </div>
</div> <!-- /padding-test -->

            
          
!
            
              // -----------------------------------
// Shorthand Generator ---------------
// -----------------------------------

@function auto($value) {
  @if $value == "a" {
    @return auto;
  } @else {
    @return $value;
  }
}

@mixin shorthander($position, $value) {
  $position-prefix: "";

  @if $position == "margin" 
   or $position == "padding" {
    $position-prefix: $position + "-";
  } @else {
    position: $position;
  }
  
  @if length($value) == 1 
  and $value != "n"
  and $value != "x"
  and $value != "null" {
    #{$position-prefix}top: auto($value);
    #{$position-prefix}right: auto($value);
    #{$position-prefix}bottom: auto($value);
    #{$position-prefix}left: auto($value);
  }

  @if length($value) == 2 {
    $value-y: nth($value, 1);
    $value-x: nth($value, 2);
    @if $value-y != "n"
    and $value-y != "x"
    and $value-y != "null" {
      #{$position-prefix}top: auto($value-y);
      #{$position-prefix}bottom: auto($value-y);
    }
    @if $value-x != "n"
    and $value-x != "x"
    and $value-x != "null" {
      #{$position-prefix}left: auto($value-x);
      #{$position-prefix}right: auto($value-x);
    }
  }

  @if length($value) == 3 {
    $value-y-top: nth($value, 1);
    $value-x: nth($value, 2);
    $value-y-bottom: nth($value, 3);

    @if $value-y-top != "n"
    and $value-y-top != "x"
    and $value-y-top != "null" {
      #{$position-prefix}top: auto($value-y-top);
    }
    @if $value-x != "n"
    and $value-x != "x"
    and $value-x != "null" {
      #{$position-prefix}right: auto($value-x);
      #{$position-prefix}left: auto($value-x);
    }
    @if $value-y-bottom != "n"
    and $value-y-bottom != "x"
    and $value-y-bottom != "null" {
      #{$position-prefix}bottom: auto($value-y-bottom);
    }
  }

  @if length($value) == 4 {
    $value-top: nth($value, 1);
    $value-right: nth($value, 2);
    $value-bottom: nth($value, 3);
    $value-left: nth($value, 4); 
    
    @if $value-top != "n"
    and $value-top != "x"
    and $value-top != "null" {
      #{$position-prefix}top: auto($value-top);
    }
    @if $value-right != "n"
    and $value-right != "x"
    and $value-right != "null" {
      #{$position-prefix}right: auto($value-right);
    }
    @if $value-bottom != "n"
    and $value-bottom != "x"
    and $value-bottom != "null" {
      #{$position-prefix}bottom: auto($value-bottom);
    }
    @if $value-left != "n"
    and $value-left != "x"
    and $value-left != "null" {
      #{$position-prefix}left: auto($value-left);
    }
  }
}

// -----------------------------------
// Shorthand Mixins ------------------
// -----------------------------------

@mixin absolute($value) {
  @include shorthander(absolute, $value);
}

@mixin relative($value) {
  @include shorthander(relative, $value);
}

@mixin fixed($value) {
  @include shorthander(fixed, $value);
}

@mixin padding($value) {
  @include shorthander(padding, $value);
}

@mixin margin($value) {
  @include shorthander(margin, $value);
}

// -----------------------------------
// Universal -------------------------
// -----------------------------------

body {
  font-family: Helvetica;
  margin: 40px;
  box-sizing: border-box;
}

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

h1 {
  font-size: 24px;
  font-weight: bold;
  margin-top: 40px;
  margin-bottom: 24px;
}

// -----------------------------------
// Tests -----------------------------
// -----------------------------------

.relative {
  position: relative;
  width: 100%;
  height: 100px;
  border: 1px solid #000;
  & + & {
    margin-top: 16px;
  }
}

.absolute,
.padding,
.margin,
.relative > .relative {
  display: block;
  background-color: #bada55;
  border: 0;
}

//
// Absolute
//

.absolute-test {
  .test-1 > .absolute {
    @include absolute(0 0 0 0);    
  }  
  .test-2 > .absolute {
    @include absolute(20px 0);  
  }
  .test-3 > .absolute {
    @include absolute(0 0 x auto);  
  }
}

//
// Relative
//

.relative-test {
  .test-1 > .relative {
    @include relative(-10px);    
  }  
  .test-2 > .relative {
    @include relative(10px x x x);  
  }
  .test-3 > .relative {
    @include relative(x x a 50%);  
  }
}

//
// Padding
//

.padding-test {
  .test-1 > .padding {
   @include padding(10px);    
  }  
  .test-2 > .padding {
   @include padding(10px x x x);  
  }
  .test-3 > .padding {
   @include padding(x x a 50%);  
  }
}

//
// Margin
//

.margin-test {
  .test-1 > .margin {
    @include margin(10px);    
  }  
  .test-2 > .margin {
    @include margin(10px x x x);  
  }
  .test-3 > .margin {
    @include margin(x x a 50%);  
  }
}
            
          
!
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.
Loading ..................

Console