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

              
                h1
 | How a CSS Diamond is Made

#whole-thing
  .steps
    .step-0
      | Imagine a box.
    .step-1
      | The box has the Cage.
    .step-2
      | The box rotates 45 degrees.
    .step-3
      | The Cage rotates -45 degrees.
    .step-4
      | The Cage zooms himself to fill gaps.
    .step-5
      | Bring up the Cage.
    .step-6
      | The box hides overflow parts.
    .step-8
      | The End.
      
  .diamond
    img(src='http://placecage.com/240/240')
 
  .triangle-title
    button#re-run
      | Run Again
  
  .inspiredby
    | Inspired by 
    a(href='https://codepen.io/chriscoyier/pen/lotjh')
      | Animation to Explain CSS Triangles
      
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Andika);

$stepTiming: 0.8s 0.2s;

.diamond {
  overflow: visible;
  margin: auto;
  width: 180px; /* option */
  height: 180px; /* option */
  outline: 2px solid blue;
  background-color: rgba(200,200,200,0.5);
  transition: $stepTiming;
  img {
    width: 100%;
    height: auto;
    opacity: 0;
    outline: 2px solid red;
    transition: $stepTiming;
  }
  .step-1 & {
    opacity: 0.5;
    img {
      opacity: 0.5;
    }
  }
  .step-2 & {
    transform: rotate(45deg);
  }
  .step-3 & {
    img {
      transform: rotate(-45deg);
    }
  }
  .step-4 & {
    img {
      width: 150%;
    }
  }
  .step-5 & {
    img {
      margin: -25%;
    }
  }
  .step-6 & {
    overflow: hidden;
  }
  .step-7 & {
    outline-color: rgba(0,0,0,0);
    img {
      opacity: 1;
      outline-color: rgba(0,0,0,0);
    }
  }
}

.triangle-title {
  width: 300px;
  padding: 1rem;
  color: white;
  border-radius: 20px;
  margin: 50px auto;
  opacity: 0;
  transition: $stepTiming;
  .step-8 & {
    opacity: 1;
  }
}

body {
  background: #333;
  font-family: 'Andika', sans-serif;
  color: white;
  text-align: center;
  font-size: large;
  transform: translateZ(0);
}

.steps {
  position: relative;
  margin-bottom: 50px;
  height: 45px;
  > div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    opacity: 0;
    background: #333;
    transition: 0.3s;
  }
  .step-0 {
    opacity: 1; 
  }
  .step-1 & .step-1 {
    opacity: 1; 
  }
  .step-2 & .step-2 {
    opacity: 1; 
  }
  .step-3 & .step-3 {
    opacity: 1; 
  }
  .step-4 & .step-4 {
    opacity: 1; 
  }
  .step-5 & .step-5 {
    opacity: 1; 
  }
  .step-6 & .step-6 {
    opacity: 1; 
  }
  .step-7 & .step-7 {
    opacity: 1; 
  }
  .step-8 & .step-8 {
    opacity: 1; 
  }
}

h1 {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 1.5rem;
  border-bottom: 1px solid #555;
  color: #999;
}

.inspiredby a {
  color: #FFF;
}
              
            
!

JS

              
                demo = $("#whole-thing")

run = () ->
  
  setTimeout ->
    demo.addClass("step-1")
  , 2500

  setTimeout ->
    demo.addClass("step-2")
  , 5000
  
  setTimeout ->
    demo.addClass("step-3")
  , 7500
  
  setTimeout ->
    demo.addClass("step-4")
  , 10000
  
  setTimeout ->
    demo.addClass("step-5")
  , 12500
  
  setTimeout ->
    demo.addClass("step-6")
  , 15000
  
  setTimeout ->
    demo.addClass("step-7")
  , 16000
  
  setTimeout ->
    demo.addClass("step-8")
  , 17500
  
run()

$("#re-run").on 'click', ->
  $("#whole-thing").removeClass()
  run()
  
              
            
!
999px

Console