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.

            
              <!-- 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>
            
          
!
            
              // 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;
}
            
          
!
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