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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!-- controls to change state - not required for effect -->
<input type="radio" name="state" class="control-flag" id="state1" checked>
<input type="radio" name="state" class="control-flag" id="state2">
<input type="radio" name="state" class="control-flag" id="state3">
<input type="radio" name="state" class="control-flag" id="state4">

<!-- DEMO -->
<div class="demo">
  <div class="clip" data-content="A clipping demo">
    A clipping demo
  </div>
</div>
<!-- /DEMO -->

<!-- controls to change state - not required for effect -->
<div class="controls">
  <label for="state1" class="controls__btn">State 1</label>
  <label for="state2" class="controls__btn">State 2</label>
  <label for="state3" class="controls__btn">State 3</label>
  <label for="state4" class="controls__btn">State 4</label>
</div>
              
            
!

CSS

              
                // colours (to make the source easier to read)
$white: #fff;
$black: #000;
$grey: #ccc;
$pink: #ff2089;
$blue: #3efdff;
$green: #eaff00;

/**
 *
 * GENERAL
 *
 */

html, body {
  height: 100%;
}

html {
  font-size: 16px; // set our root font size
}

body {
  font-family: Arial, Helvetica, sans-serif;
  margin: 0;
}

/**
 *
 * DEMO (default = state1)
 *
 */

.demo {
  height: 100%;
  background: $green;
  color: $black;
  transition: background 500ms;
}

.clip {
  // style the text
  font-family: 'Work Sans', Arial, Helvetica, sans-serif;
  font-weight: 800;
  font-size: 8rem;
  text-align: center;
  text-transform: uppercase;
  
  // position self (&) and pseudo elements (before / after)
  &,
  &::before,
  &::after {
    // fill the page
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    // centre the text
    display: flex;
    justify-content: center;
    align-items: center;
    
    // trick: squeeze the text to get it to wrap
    padding: 0 50%;
    box-sizing: border-box;
  }
  
  &::before,
  &::after {
    // read the text from the HTML instead of hardcoding in the CSS
    content: attr(data-content);
    // set the transition on the clip-path property
    transition: clip-path 500ms;
  }
  
  &::before {
    color: $white;
    background: $pink;
    // clip the ::before element diagonally to hide the bottom left
    clip-path: polygon(0 0, 100% 0, 0 100%, 0 100%);
  }
  
  &::after {
    color: $pink;
    background: $blue;
    // clip the ::after element diagonally to hide the top left
    clip-path: polygon(100% 0, 100% 100%, 0 100%, 100% 0);
  }
}

/**
 *
 * STATES - state2
 *
 */

#state2:checked {
  ~ {
    .demo {
      .clip {
        &::before {
          // pull the triangle back slightly to reveal the background
          clip-path: polygon(0 0, 80% 0, 0 100%, 0 100%);
        }
        &::after {
          // pull the triangle back slightly to reveal the background
          clip-path: polygon(100% 0, 100% 100%, 20% 100%, 100% 0);
        }
      }
    }
  }
}

/**
 *
 * STATES - state3
 *
 */
#state3:checked {
  ~ {
    .demo {
      background: $white;
      .clip {
        &::before {
          // use our extra point to create a square on the left
          clip-path: polygon(0 0, 40% 0, 40% 100%, 0 100%);
        }
        &::after {
          // and a square on the right
          clip-path: polygon(100% 0, 100% 100%, 60% 100%, 60% 0);
        }
      }
    }
  }
}


/**
 *
 * STATES - state4
 *
 */
#state4:checked {
  ~ {
    .demo {
      .clip {
        &::before {
          // twist the clip path horizontally
          clip-path: polygon(100% 0, 0 0, 100% 100%, 0 100%);
        }
        &::after {
          // twist the clip path vertically
          clip-path: polygon(100% 0, 100% 100%, 0 0, 0 100%);
        }
      }
    }
  }
}

/**
 *
 * CONTROLS (not required for effect)
 *
 */

.control-flag {
  position: absolute;
  left: -9999px;
}

.controls {
  position: fixed;
  z-index: 10;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  padding: 20px 0;
}

.controls__btn {
  display: inline-block;
  padding: 5px;
  background: $white;
  color: $black;
  cursor: pointer;
}

// show active state
#state1:checked ~ .controls .controls__btn[for="state1"],
#state2:checked ~ .controls .controls__btn[for="state2"],
#state3:checked ~ .controls .controls__btn[for="state3"],
#state4:checked ~ .controls .controls__btn[for="state4"]{
  background: $black;
  color: $white;
  cursor: default;
}
              
            
!

JS

              
                
              
            
!
999px

Console