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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              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
Loading ..................

Console