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.

            
              <div class="item-1">A black square appears after me...&nbsp;</div>

<div class="item-2">A red square appears before me...&nbsp;</div>

<div class="item-3">A blue square appears in the upper right corner...&nbsp;</div>

<div class="item-4">A green square appears before me...&nbsp;</div>
            
          
!
            
              /// Define accepted values for certain CSS properties
/// @type String
$position-values: "fixed",
                  "absolute",
                  "relative",
                  "static";

/// @type String
$display-values: "block",
                 "flex",
                 "inline-block",
                 "inline-flex",
                 "inline-table",
                 "list-item",
                 "run-in",
                 "table",
                 "table-caption",
                 "table-column-group",
                 "table-header-group",
                 "table-footer-group",
                 "table-row-group",
                 "table-cell",
                 "table-column",
                 "table-row",
                 "none",
                 "initial",
                 "inherit";

@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 if $position == "null" {
    // do nothing
  } @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);
    }
  }
}

@mixin position($value, $position: null) {
  // Allow user to enter value in either position
  // - If user supplies a position for the value ...
  // - Swap the position variable for the value variable
  // - Note: Accepted values for $position found in `_upbase-default-settings.scss`
  @if list-contains($position-values, $value) {
    $true-position: $value;
    $value: $position;
    $position: $true-position;
    @warn "Looks like you mixed up the position and the value."
        + "We tried to fix it by swapping the values, but you"
        + "should double-check to see you got what you expected."
  }

  @include shorthander($position, $value);
}

@function list-contains($list, $value) {
  @return not not index($list, $value);
}

@function list-does-not-contain($list, $value) {
  @return not index($list, $value);
}

@mixin pseudo(
  $coordinates: null,
  $position: absolute,
  $display: block) {

  // Allow user to enter positioning value/coordinates in either position
  // - If user supplies a position for the value ...
  // - Swap the position variable for the value variable
  // - Note: Accepted values for $position found in `_upbase-default-settings.scss`
  @if list-contains($position-values, $coordinates) {
    // Store true position
    $true-position: $coordinates;

    // Check if $position has been filled out
    @if $position != absolute {
      $coordinates: $position;
    } else {
      $position: null;
    }

    // Set true position 
    $position: $true-position;
    @warn "Looks like you mixed up the position and the value."
        + "We tried to fix it by declaring `#{$position}` as the position"
        + "and setting `#{$coordinates}` as the coordinates"
        + "Please check to see you got the output you expected."
  }

  // - If user supplies a display value for the coordinates ...
  // - Replace the display variable with the coordinates variable
  // - Note: Accepted values for $display found in `_upbase-default-settings.scss`
  @if list-contains($display-values, $coordinates) {
    $true-display: $coordinates;
    $coordinates: null;
    $display: $true-display;
    @warn "Looks like you want to declare the display of the pseudo element."
        + "Your declaration `#{$display}`  is out of sequence, but we tried to fix it."
        + "Please double-check to see you have the output you expect."
  }

  // - If user supplies an invalid value for position, warn them ...
  @if list-contains($position-values, $position) {
    // If true, do nothing
  } @else {
    @warn "It doesn't look like `#{$position}` is a valid position value."
        + "Double-check to see you have the output you expect."
        + "Accepted values for position values found in `_upbase-default-settings.scss`"
  }

  content: "\0020";
  display: $display;
  @if $coordinates != null 
  and $position != null {
    @include position($coordinates, $position);
  }
}

.item-1,
.item-2,
.item-3,
.item-4{
  position: relative;
  margin-bottom: 30px;
  max-width: 250px;
}

.item-2 {
  margin-left: 15px;
}

.item-1:after {
  @include pseudo(inline-block);
  height: 10px;
  width: 10px;
  background-color: black;
}

.item-2:before {
  @include pseudo(4px x x -15px);
  height: 10px;
  width: 10px;
  background-color: red;
}

.item-3:after {
  @include pseudo(0 0 0 x, fixed);
  height: 10px;
  width: 10px;
  background-color: blue;
}

.item-4:before {
  @include pseudo(4px x x 100%, absolute, flex);
  height: 10px;
  width: 10px;
  background-color: #bada55;
}
            
          
!
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