cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console