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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="scene">
  <div class="background"></div>
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/c3po-foreground-test_copy.png" alt="" class="foreground">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/c3po-base-test.png" alt="" class="base">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/c3po--base-1_copy.png" alt="" class="base-2">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/title_copy.png" alt="" class="logo">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/c3po-eyes_copy.png" alt="" class="eyes">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/36124/c3po-profile_copy_copy.png" alt="" class="profile">
  <div class="frame"></div>
<!--   <div class="floor"></div> -->
</div>

<div class="credit">
  <a class="credit__link" href="http://ollymoss.com/" target="_blank" rel="noopener noreferrer" title="Olly Moss">Poster By Olly Moss</a>
</div>
              
            
!

CSS

              
                /** LOTS of magic numbers here. Proof of concept. Barely responsive. **/

* {
  box-sizing: border-box;
}

:root {
  --move-x: 0deg;
  --move-y: 0deg;
}

body {
  height: 100vh;
  background: url("https://images.unsplash.com/photo-1504812333783-63b845853c20?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=7668266ab50622d9d6ebcc1a69cdb3e2");
  background-size: cover;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.scene {
  width: 600px;
  height: 897px;
  margin: 20px auto;
  padding: 0;
  perspective: 600px;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
  transform: scale(0.7) rotateY(var(--move-x)) rotateX(var(--move-y));
  
  @media screen and (max-width: 660px) {
    width: 300px;
    height: 448.5px;
    perspective: 700px;
  }
}

.scene img {
  width: 600px;
  height: 897px;
  
  @media screen and (max-width: 660px) {
    width: 300px;
    height: 448.5px;
  }
}

.foreground {
  max-width: 100%;
  display: block;
  width: auto;
  height: auto;
  position: absolute;
  left: 0;
  z-index: 2;
  transform: scale(1.1) translateY(-50px);
  transform-style: preserve-3d;
}

.logo {
  display: block;
  max-width: 100%;
  position: absolute;
  left: 0;
  transform: translateZ(100px) translateY(-75px);
  z-index: 2;
  
  @media screen and (max-width: 660px) {
    transform: translateZ(150px) translateY(-40px) scale(0.7);
  }
}

.base {
  display: block;
  max-width: 100%;
  position: absolute;
  left: 0;
  transform: translateZ(-150px) scale(1.2) translateY(-50px);
}

.base-2 {
  display: block;
  max-width: 100%;
  position: absolute;
  left: 0;
  transform: translateZ(-50px) translateY(-50px) scale(1.2);
}

.eyes {
  display: block;
  max-width: 100%;
  position: absolute;
  left: 0;
  transform: translateZ(0px) translateY(-50px);
}

.profile {
  display: block;
  max-width: 100%;
  position: absolute;
  left: 0;
  transform: translateZ(50px) translateY(-60px);
}

.frame {
  width: calc(100% + 200px);
  height: 0;
  padding-top: 145.88%;
  position: absolute;
  left: -100px;
  top: -140px;
  transform: translateZ(50px);
  border: 100px solid #ffffff;
  transform-style: preserve-3d;

  &:before {
    position: absolute;
    width: 200px;
    height: auto;
    bottom: -100px;
    top: -100px;
    content: "";
    display: block;
    background: #ffffff;
    left: -300px;
    transform-origin: 100% 50%;
    transform: rotateY(-60deg); // need this offset a bit, not a right angle
  }

  &:after {
    position: absolute;
    width: 200px;
    height: auto;
    top: -100px;
    right: -300px;
    bottom: -100px;
    content: "";
    display: block;
    background: #ffffff;
    transform-origin: 0% 50%;
    transform: rotateY(60deg);
  }
  
  
}

.background {
  position: absolute;
  width: 140%;
  height: 110%;
  padding-top: 66%;
  float: left;
  background: #ff1747;
  left: -20%;
  top: -10%;
  transform: translateZ(-165px) scale(1.2);
}


.credit {
  position: fixed;
  bottom: 1em;
  width: 100%;
  text-align: center;
}

.credit__link {
  background-color: black;
  color: white;
  text-decoration: none;
  padding: 4px 6px;
  font-family: -apple-system, BlinkMacSystemFont, "San Francisco",
    "Helvetica Neue", Helvetica, Ubuntu, Roboto, Noto, "Segoe UI", Arial,
    sans-serif;
  font-size: 12px;
  font-weight: bold;
  line-height: 1.2;
  display: inline-block;
  border-radius: 3px;
}

              
            
!

JS

              
                const body = document.querySelector("body")
const bodyDims = {
  w: body.getBoundingClientRect().width,
  h: body.getBoundingClientRect().height
}
const limit = {
  x: 45,
  y: 15
}

body.addEventListener("mousemove", e => {
  const mouse = {
    x: e.pageX,
    y: e.pageY
  }
  const clamped = {
    x: mouse.x / bodyDims.w * limit.x - limit.x / 2,
    y: mouse.y / bodyDims.h * limit.y - limit.y / 2
  }
  document.documentElement.style.setProperty("--move-x", clamped.x + "deg")
  document.documentElement.style.setProperty("--move-y", -clamped.y + "deg")
})

window.addEventListener('deviceorientation', e => {
  const tilt = {
    x: e.gamma,
    y: e.beta
  };
  document.documentElement.style.setProperty("--move-x", tilt.x*-0.3 + "deg")
  document.documentElement.style.setProperty("--move-y", tilt.y*-0.3 + "deg")
});
              
            
!
999px

Console