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.

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