css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              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
      
            
          
!
            
              @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;
}
            
          
!
            
              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
🕑 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