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

              
                <main>
  <article>
    <section id="perspective">
      <svg id="grid">
        <rect x="1" y="1" width="998" height="998"/>
        <line x1="200" y1="2" x2="200" y2="998"/>
        <line x1="400" y1="2" x2="400" y2="998"/>
        <line x1="600" y1="2" x2="600" y2="998"/>
        <line x1="800" y1="2" x2="800" y2="998"/>
        <line x1="2" y1="200" x2="998" y2="200"/>
        <line x1="2" y1="400" x2="998" y2="400"/>
        <line x1="2" y1="600" x2="998" y2="600"/>
        <line x1="2" y1="800" x2="998" y2="800"/>
      </svg>
      <section id="axis">
        <figure id="X">
          <div class="front"></div>
          <div class="back"></div>
          <div class="left"></div>
          <div class="right"></div>
          <div class="top"></div>
          <div class="bottom"></div>
        </figure>
        <figure id="Y">
          <div class="front"></div>
          <div class="back"></div>
          <div class="left"></div>
          <div class="right"></div>
          <div class="top"></div>
          <div class="bottom"></div>
        </figure>
        <figure id="Z">
          <div class="front"></div>
          <div class="back"></div>
          <div class="left"></div>
          <div class="right"></div>
          <div class="top"></div>
          <div class="bottom"></div>
        </figure>
      </section>
      <section id="graph"></section>
    </section>
  </article>
  <nav>
    <button onmousedown="select(this)">Pan</button>
    <button onmousedown="select(this)">Rotate</button>
    <button onmousedown="select(this)">Zoom</button>
    <button onmousedown="resetViewport()">Reset viewport</button>
    <section id="menu">Your menu</section>
  </nav>
  <label>‹</label>
  <label id="info">ⓘ</label>
  <aside>
    <p>This CSS 3D project works fine only in WebKit based browsers</p>
    <p>Middle mouse button - Pan view</p>
    <p>Alt + Left mouse button - Rotate view</p>
    <p>Scroll wheel - Zoom in / out</p>
  </aside>
</main>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}

body {
  width: 100vw;
  height: 100vh;
  font-family: Trebuchet MS;
  background: #191919;
  user-select: none;
}

main {
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: hidden;
}

article {
  width: 100%;
  height: 100%;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1250px;
}
article.pan { cursor: -webkit-grab; }
article.rotate { cursor: url('http://www.leocad.org/trac/export/1598/tags/leocad-0.79.1/win/res/rotate.cur'), auto; }
article.zoom { cursor: n-resize; }

#perspective {
  margin-top: 100px;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform: rotateX(-20deg) rotateY(-45deg);
}
#perspective.reset {
  transition: transform 1s ease-in-out;
}

#grid {
  margin: -500px;
  width: 1000px;
  height: 1000px;
  opacity: 0.7;
  transform: rotateX(90deg);
}
rect {
  stroke: white;
  stroke-width: 1px;
  fill: transparent;
}
line {
  stroke: white;
  stroke-width: 1px;
}

#axis, #graph {
  margin-top: -6px;
  width: 0;
  height: 0;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(90deg);
}

#axis { opacity: 0.4; }

#X, #Y, #Z, #X div, #Y div, #Z div, .point, .point div {
  width: 2px;
  height: 2px;
  position: absolute;
}

#X, #Y, #Z, .point {
  top: -1px;
  left: -1px;
  transform-style: preserve-3d;
}

#X { transform: translateX(1px) rotateY( 90deg); }
#Y { transform: translateY(1px) rotateX(-90deg); }
#Z { transform: translateZ(1px); }

#X div { background: #f56931; }
#Y div { background: #27c26f; }
#Z div { background: #31bdf5; }

#X .front,  #Y .front,  #Z .front  { transform: translateZ(500px) rotateY(0deg); }
#X .back,   #Y .back,   #Z .back   { transform: rotateY(180deg); }
#X .left,   #Y .left,   #Z .left   { width:  500px; transform: translate3d(-250px, 0, 250px) rotateY(-90deg); }
#X .right,  #Y .right,  #Z .right  { width:  500px; transform: translate3d(-248px, 0, 250px) rotateY( 90deg); }
#X .top,    #Y .top,    #Z .top    { height: 500px; transform: translate3d(0, -250px, 250px) rotateX( 90deg); }
#X .bottom, #Y .bottom, #Z .bottom { height: 500px; transform: translate3d(0, -248px, 250px) rotateX(-90deg); }

.point div { background: tomato; }

.point .front  { transform: translateZ( 1px) rotateY(  0deg); }
.point .back   { transform: translateZ(-1px) rotateY(180deg); }
.point .left   { transform: translateX(-1px) rotateY(-90deg); }
.point .right  { transform: translateX( 1px) rotateY( 90deg); }
.point .top    { transform: translateY(-1px) rotateX( 90deg); }
.point .bottom { transform: translateY( 1px) rotateX(-90deg); }

label {
  position: absolute;
  color: #999;
}
#info {
  padding: 10px;
  font-size: 50px;
  cursor: pointer;
}
aside {
  padding: 28px 10px;
  position: absolute;
  left: 60px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#info:hover ~ aside {
  opacity: 1;
}
p {
  padding: 5px;
  font-size: 16px;
  color: #aaa;
}
p:first-child {
  margin-bottom: 10px;
  font-weight: bold;
  font-size: 17px;
}

nav {
  padding: 20px;
  width: 300px;
  height: 100vh;
  position: absolute;
  right: 0px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  overflow: auto;
  background: #222;
  box-sizing: border-box;
  transform: translateX(267px);
  transition: transform 0.2s ease-in-out;
}
nav:hover { transform: translateX(0px); }

nav + label {
  top: calc(50% - 0.7em);
  right: -1px;
  font-size: 90px;
  pointer-events: none;
  transition: transform 0.35s ease-out;
}
nav:hover + label {
  transform: translate(-330px, 12px) rotate(180deg);
}

button {
  margin: 10px 5px;
  padding: 5px 10px;
  border: solid 1px #999;
  border-radius: 5px;
  font: 18px Trebuchet MS;
  color: #999;
  background: transparent;
  cursor: pointer;
  outline: none;
}
button:hover {
  border-color: #aaa;
  color: #aaa;
}
button:active, button.selected {
  color: #eee;
}
#menu {
  margin: 15px;
  margin-bottom: 10px;
  padding: 20px;
  width: 100%;
  height: 500px;
  text-align: center;
  font: 18px Trebuchet MS;
  color: #999;
  background: #272727;
}
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb {
  border-right: solid 5px #222;
  background: #5f5f5f;
}
              
            
!

JS

              
                var $ = document.querySelectorAll.bind(document);

/* -------------------------------- */
/* ---------- Navigation ---------- */
/* -------------------------------- */
var article = $('article')[0];
var perspective = $('#perspective')[0];
var buttons = $('button');

var click = false;
var cursor = { x: 0, y: 0 };
var transform = {
  position: { x: 0, y: 0 },
  rotation: { x: 0, y: 0 },
  zoom: 0
};
var target = {
  position: { x: 0, y: 0 },
  rotation: { x: -20, y: -45 },
  zoom: 100
};
var targetOnDown = {
  position: { x: 0, y: 0 },
  rotation: { x: 0, y: 0 },
  zoom: 0
};

article.onmousedown = function(e) {
  if (e.which < 3) {
    if (e.which == 2) article.className = 'pan';
    if (article.className == 'pan')
      article.style.cursor = '-webkit-grabbing';
    cursor.x = e.pageX;
    cursor.y = e.pageY;
    targetOnDown.position.x = target.position.x;
    targetOnDown.position.y = target.position.y;
    targetOnDown.rotation.x = target.rotation.x;
    targetOnDown.rotation.y = target.rotation.y;
    targetOnDown.zoom = target.zoom;
    click = true;
  }
};
article.onmousemove = function(e) {
  if (click) {
    switch (article.className) {
      case 'pan':    target.position.x = targetOnDown.position.x + e.pageX - cursor.x;
                     target.position.y = targetOnDown.position.y + e.pageY - cursor.y;
                     break;

      case 'rotate': target.rotation.x = targetOnDown.rotation.x - (e.pageY - cursor.y) * 0.3;
                     target.rotation.y = targetOnDown.rotation.y + (e.pageX - cursor.x) * 0.3;
                     break;

      case 'zoom':   target.zoom = targetOnDown.zoom - (e.pageY - cursor.y) * 0.4;
                     if (target.zoom < 50) target.zoom = 50;
                     break;
    }
  }
};
article.onmouseup = function(e) {
  click = false;
  if (article.className == 'pan')
    article.style.cursor = '';
  if (e.which == 2) returnValue();
};

onkeydown = function(e) {
  if (e.altKey) article.className = 'rotate';
};
onkeyup = function(e) {
  if (e.keyCode == 18) returnValue();
};

article.addEventListener('mousewheel', scroll, false);
article.addEventListener('DOMMouseScroll', scroll, false);
function scroll(e) {
  e.preventDefault();
  var delta = (e.wheelDelta) ? e.wheelDelta : - e.detail;
  target.zoom += (delta > 0) ? 15 : -15;
  if (target.zoom < 50) target.zoom = 50;
}

function select(button) {
  [].forEach.call(buttons, function(b) { if (b != button) b.removeAttribute('class'); });
  (button.className) ? button.removeAttribute('class') : button.className = 'selected';
  switch (button.innerHTML) {
    case 'Pan': (article.className == 'pan') ? article.removeAttribute('class') : article.className = 'pan'; break;
    case 'Rotate': (article.className == 'rotate') ? article.removeAttribute('class') : article.className = 'rotate'; break;
    case 'Zoom': (article.className == 'zoom') ? article.removeAttribute('class') : article.className = 'zoom'; break;
  }
}

function returnValue() {
  for (var i = 0; i < buttons.length; i++)
    if (buttons[i].className == 'selected')
      var str = buttons[i].innerHTML.toLowerCase();
  if (str) article.className = str;
  else article.removeAttribute('class');
}

function resetViewport() {
  target.position.x = target.position.y = 0;
  target.rotation.x = -20;
  target.rotation.y = -45;
  target.zoom = 100;
}

(function animate() {
  transform.position.x += (target.position.x - transform.position.x) * 0.2;
  transform.position.y += (target.position.y - transform.position.y) * 0.2;
  transform.rotation.x += (target.rotation.x - transform.rotation.x) * 0.1;
  transform.rotation.y += (target.rotation.y - transform.rotation.y) * 0.1;
  transform.zoom += (target.zoom - transform.zoom) * 0.1;

  transform.position.x = parseFloat(transform.position.x.toFixed(2));
  transform.position.y = parseFloat(transform.position.y.toFixed(2));
  transform.rotation.x = parseFloat(transform.rotation.x.toFixed(2));
  transform.rotation.y = parseFloat(transform.rotation.y.toFixed(2));
  transform.zoom = parseFloat(transform.zoom.toFixed(2));

  perspective.style.transform =
  perspective.style.msTransform =
  perspective.style.mozTransform =
  perspective.style.webkitTransform = 'translate(' + transform.position.x + 'px, ' + transform.position.y + 'px) rotateX(' + transform.rotation.x + 'deg) rotateY(' + transform.rotation.y + 'deg) scale3d(' + transform.zoom / 100 + ', ' + transform.zoom / 100 + ', ' + transform.zoom / 100 + ')';
  requestAnimationFrame(animate);
})();

/* -------------------------------- */
/* -------- Graph Plotting -------- */
/* -------------------------------- */

var graph = $('#graph')[0];

for (var x = -6; x <= 6; x++) {
  for (var y = -6; y <= 6; y++) {
    var z = Math.pow(x, 2) + Math.pow(y, 2);
    var point = document.createElement('figure');
    point.className = 'point';
    point.innerHTML = '<div class="front"></div><div class="back"></div><div class="left"></div><div class="right"></div><div class="top"></div><div class="bottom"></div>';
    point.style.transform =
    point.style.msTransform =
    point.style.mozTransform =
    point.style.webkitTransform = 'translate3d('+(x*25)+'px,'+(y*25)+'px,'+(z*3)+'px)';
    graph.appendChild(point);
  }
}
              
            
!
999px

Console