Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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>3D Box <span>With Pure CSS</span></h1>

<section class="container">
  <div id="box" class="box show-front">
    <figure class="front"></figure>
    <figure class="back"></figure>
    <figure class="right"></figure>
    <figure class="left"></figure>
    <figure class="top"></figure>
    <figure class="bottom"></figure>
  </div>
</section>
 
<ul id="options">
   <li><button class="current show-front">Front</button></li>
   <li><button class="show-back">Back</button></li>
   <li><button class="show-right">Right</button></li>
   <li><button class="show-left">Left</button></li>
   <li><button class="show-top">Top</button></li>
   <li><button class="show-bottom">Bottom</button></li>
   <!--
   <li><button id="toggle-backface-visibility">Toggle Backface Visibility</button></li>
   -->
</ul>

<p class="help">Rollover box to see the backface!</p>
<p class="link">See the <a href="https://codepen.io/wallaceerick/pen/ojtal">Pure CSS Tabs</a> demo!</p>


<!-- TO DO
<h1>Other Samples <span>With Different Positions</span></h1>


<section class="container">
  <div id="box" class="box show-front">
    <figure class="front"></figure>
    <figure class="back"></figure>
    <figure class="right"></figure>
    <figure class="left"></figure>
    <figure class="top"></figure>
    <figure class="bottom"></figure>
  </div>
</section>
-->
              
            
!

CSS

              
                @import "compass/css3";

@import url("https://font.googleapis.com/css?family=Lato");

//CONFIG
$box-width: 300px;
$box-height: $box-width / 1.5;
$primary-color: #9b59b6;
$secundary-color: #8e44ad;

* {
  margin: 0;
  padding: 0; 
  @include box-sizing(border-box);
}
body {
  text-align: center;
  background: $primary-color;
  padding: 20px;
  font-family: Lato;
  color: #fff;
}
h1 {
  font-weight: normal;
  font-size: 40px;
  font-weight: normal;
  text-transform: uppercase; 
  margin: 20px 0 10px 10px; 
  span { 
    font-size: 13px;
    display: block;
    padding-left: 4px;
  } 
}

//BOX
.container {
      width: $box-width;
      height: $box-height; 
      position: relative;
      margin: 40px auto 80px auto;
      //border: 1px solid #CCC;
      @include perspective(1200px);
    }

    .box {
      width: 100%;
      height: 100%;
      position: absolute;
      @include transform-style(preserve-3d);
      @include transition(transform 0.5s);
      figure {
          display: table;
          position: absolute;  
          text-align: center; 
          color: white;
      }
    }
    
    //Sizes
    .box .front,
    .box .back {
      width: $box-width;
      height: $box-height;
    } 
    .box .right,
    .box .left {
      width: $box-width / 3;
      height: $box-height;
    } 
    .box .top,
    .box .bottom {
      width: $box-width;
      height: $box-width / 3;
    }

    //Positions
    .box .right,
    .box .left {
      left: $box-width / 3;
    } 
    .box .top,
    .box .bottom {
      top: $box-height / 4;
    }

    //Colors
    .box .front,
    .box .back   { background: darken($secundary-color, 5%);}
    .box .right,
    .box .left,
    .box .top,
    .box .bottom { background: darken($secundary-color, 15%);}
    
    //Transforms
    .box .front  {
      @include transform(translateZ($box-height / 4));
    }
    .box .back   {
      @include transform(rotateX(-180deg) translateZ($box-height / 4));
    }
    .box .right  {
      @include transform(rotateY(90deg) translateZ($box-width / 2));
    }
    .box .left {
      @include transform(rotateY(-90deg) translateZ($box-width / 2));
    }
    .box .top {
      @include transform(rotateX(90deg) translateZ($box-height / 2));
    }
    .box .bottom {
      @include transform(rotateX(-90deg) translateZ($box-height / 2));
    }

    //Show Specific Face
    .box.show-front {
      @include transform(translateZ($box-height / -4));
    }
    .box.show-back {
      @include transform(translateZ($box-height / -4) rotateX(-180deg));
    }
    .box.show-right {
      @include transform(translateZ($box-width / -2) rotateY(-90deg));
    }
    .box.show-left {
      @include transform(translateZ($box-width / -2) rotateY(90deg));
    }
    .box.show-top {
      @include transform(translateZ($box-height / -2) rotateX(-90deg)); 
    }
    .box.show-bottom {
      @include transform(translateZ($box-height / -2) rotateX(90deg));
    }
    
    //Rollover
    .box:hover {
      @include transform(rotateX(-180deg) translateZ($box-height / 4));
    }
//Buttons
ul#options {
  list-style: none;
  display: table;
  margin-left: auto;
  margin-right: auto; 
  li {
    float: left;
    margin-right: 5px;
    button {
      outline: none;
      display: block;
      cursor: pointer;
      border: none;
      padding: 10px 20px;
      color: #fff;
      font-family: 'Lato';
      text-transform: uppercase;
      font-size: 14px;
      background: darken($secundary-color, 5%);
      @include border-radius(2px);
      @include transition(all 0.2s ease-in);
      &:hover {
        background: darken($secundary-color, 15%);
      }
      &.current {
        background: darken($secundary-color, 20%);
      }
    }
  }
}

p.help {
  text-transform: uppercase;
  margin: 20px;
}
p.link {
  clear: both;
  margin-top: 40px;
  a {
    text-transform: uppercase;
    text-decoration: none;
    display: inline-block;
    color: #fff;
    padding: 5px 10px;
    margin: 0 5px;
    background-color: darken($secundary-color, 5);
    @include transition(all 0.2s ease-in);
    &:hover {
      background-color: darken($secundary-color, 20);
    }
  }
}
              
            
!

JS

              
                /*
REFERENCE:
http://24ways.org/2010/intro-to-css-3d-transforms/ 
by David DeSandro
*/
var init = function() {
  var box = document.querySelector('.box'),
      showPanelButtons = document.querySelectorAll('ul#options li button'),
      panelClassName = 'show-front',

      onButtonClick = function( event ){
        box.removeClassName( panelClassName );
        panelClassName = event.target.className;
        box.addClassName( panelClassName );
      };
var poewr;
  for (var i=0, len = showPanelButtons.length; i < len; i++) {
    showPanelButtons[i].addEventListener( 'click', onButtonClick, false);
  }
  
  document.getElementById('toggle-backface-visibility').addEventListener( 'click', function(){
    box.toggleClassName('panels-backface-invisible');
  }, false);
  
};
  
window.addEventListener( 'DOMContentLoaded', init, false);


//Only to Demo
$('button').click(function(){
  $('ul#options li button').removeClass('current');
  $(this).addClass('current');
});
              
            
!
999px

Console