Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                %header.nite
    %h1 CSS Clipping Path 
    %p
        Single element, basic shape clipping with no SVG markup. Based on this <a href="http://www.w3.org/TR/2013/WD-css-shapes-1-20130620/">W3C working draft of 6/2013.</a>
    %p
        Update: Added excellent animations by <a href="https://codepen.io/jakealbaugh">@jakealbaugh</a>
.polygon.shape Polygon

.circle.shape Circle

.ellipse.shape Ellipse

.rectangle.shape Rectangle

.inset-rectangle.shape Inset Rectangle

.shape Original, no clip
              
            
!

CSS

              
                $polygon: polygon(
    /* X and Y points */
    0 30%,
    30% 0,
    100% 0,
    100% 70%,
    70% 100%,
    0 100%
  );
;

$circle: circle(
    50%, /* X center point */
    50%, /* Y center point */
    45%  /* Radius Length */
  );
;

$ellipse: ellipse(
    50%, /* X center point */
    50%, /* Y center point */
    50%,  /* X Radius Length */
    25%  /* Y Radius Length */    
  );
;

$rectangle: rectangle(
    0,   /* X Position */
    25%, /* Y Position */
    100%, /* Width */
    50%,  /* Height */
    
    /* Optional Rounded Corners */
    15px,  /* X Radius*/
    15px   /* Y Radius */
  );
;

/* Inset rectangle is basically rectangle with different syntax */
$inset-rectangle: inset-rectangle(
    10px, /* Top Inset */
    10px, /* Right Insert */
    10px, /* Bottom Inset */
    10px, /* Left Inset */
    
    /* Optional Rounded Corners */
    10px,  /* X Radius*/
    10px   /* Y Radius */
  );
;

/* Animate these CSS shapes

Thanks to Jake Albaugh

Current interpolation between different CSS shapes is not great (ie. from circle to rectangle)

For this "reset" to animate smoothly, we need to redefine the clip path on hover using the same CSS shape function.

The idea is to redraw the path either the same size as the original div, or larger, because any excess shape (like in circles) will get clipped by the div itself.

The shape will appear to morph back in the dimensions of the div when in actuality, it's just filling up all the the space inside the div.
*/

$polygon-reset: polygon(0 0, 50% 0, 100% 0, 100% 50%, 100% 100%, 0 100%);
$circle-reset: circle(50%, 50%, 100%);
$ellipse-reset: ellipse(50%, 50%, 100%, 100%);
$rectangle-reset: rectangle(0, 0, 100%, 100%, 0px, 0px);
$inset-rectangle-reset: inset-rectangle(0,0,0,0,0,0);

.polygon {
  -webkit-clip-path: $polygon;
  &:hover {
    -webkit-clip-path: $polygon-reset;
  }
}

.circle {
  -webkit-clip-path: $circle;
  &:hover {
    -webkit-clip-path: $circle-reset;
  }
}

.ellipse {
  -webkit-clip-path: $ellipse;
  &:hover {
    -webkit-clip-path: $ellipse-reset;
  }
}

.rectangle {
  -webkit-clip-path: $rectangle;
  &:hover {
    -webkit-clip-path: $rectangle-reset;
  }
}

.inset-rectangle {
  -webkit-clip-path: $inset-rectangle;
  &:hover {
    -webkit-clip-path: $inset-rectangle-reset;
  }
}


.shape {
  width: 150px;
  height: 150px;  
  margin: 30px auto;
  
  background: rgba(0,160,250, .6);
  
  font-family: 'Open Sans';
  font-weight: 300;
  font-size: 16px;
  line-height: 150px;
  text-align: center;
  
  color: #eee;
  
  transition: all 200ms ease-out;
}

.shape:hover {
  box-shadow: inset 1px 1px #ccc, inset -1px -1px #ccc;
  background: rgba(0,0,0,.05);
  color: #999;
}

body {
  background: url('https://rawgithub.com/subtlepatterns/SubtlePatterns/gh-pages/tiny_grid.png');
}
              
            
!

JS

              
                
              
            
!
999px

Console