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

              
                <input type="checkbox" id="view-cells" />
<label for="view-cells">
  View Cells
</label>
<input type="checkbox" id="more" />
<label for="more">
  More rotation!
</label>
<div class="hover-img-container">
  <div class="top-left">top left</div>
	<div class="top-right">top right</div>
	<div class="bottom-left">bottom left</div>
	<div class="bottom-right">bottom right</div>
	<div class="top-middle">top middle</div>
	<div class="bottom-middle">bottom middle</div>
	<img src="https://i.imgur.com/sVpcrkO.jpeg" alt="Close up of a happy red fox laying down in the woods" />
</div>
              
            
!

CSS

              
                /* Center placement & color */
html { display: grid; height: 100%; place-items: center; background-color: #080011; color: white; font-family: system-ui; padding: 20px; box-sizing: border-box }

:root {
  /* Make a variable for how much you want
  the image to rotate by */
  --rotation: 5deg
}

.hover-img-container {
  /* make sure inner absolutely positioned 
  elements is relative to this container */
	position: relative;
	width: 500px;
	height: 300px;
  /* This property determines the distance between
  the camera and the z-axis to give the 3d rotations
  on the image some perspective
  https://developer.mozilla.org/en-US/docs/Web/CSS/perspective */
  perspective: 1000px;
  /* zoom entire thing on hover */
  transition: transform .2s;
  &:hover {
    transform: scale(1.02)
  }
}
.hover-img-container img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	border-radius: 12px;
  /* Make sure the image transtions smoothly between transforms */
  transition: transform .7s cubic-bezier(0,0,0,1);
}

.hover-img-container div {
  /* Start the cells with a size */
  position: absolute;
  width: 50%;
  height: 50%;
  z-index: 2;
}
.hover-img-container {
  .top-left {
    /* position the cell */
    top: 0;
    left: 0;
    /* When hovering over this cell, 
    select the image after this cell and apply the rotation */
    &:hover ~ img {
      /* rotate3d(x, y, z, angle) 
      https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d */
      transform: rotate3d(-1, 1, 0, var(--rotation))
    }
  }
  /* Do the same for the rest of the cells */
  .top-right {
    top: 0;
    right: 0;
    &:hover ~ img {
      transform: rotate3d(-1, -1, 0, var(--rotation))
    }
  }
  .bottom-left {
    bottom: 0;
    left: 0;
    &:hover ~ img {
      transform: rotate3d(1, 1, 0, var(--rotation))
    }
  }
  .bottom-right {
    bottom: 0;
    right: 0;
    &:hover ~ img {
      transform: rotate3d(1, -1, 0, var(--rotation)) 
    }
  }
  /* For the top and bottom middle cells, i removed the width
  and relied on left & right anchoring (inset property)*/
  .top-middle {
    top: 0;
    bottom: 50%;
    inset-inline: 35% !important;
    width: unset;
    height: unset;
    &:hover ~ img {
      transform: rotate3d(-1, 0, 0, var(--rotation))
    }
  }
  .bottom-middle {
    top: 50%;
    bottom: 0;
    inset-inline: 35% !important;
    width: unset;
    height: unset;
    &:hover ~ img {
      transform: rotate3d(1, 0, 0, var(--rotation))
    }
  }  
}

/* unrelated just for demo */
.hover-img-container {
  margin-top: 5px;
  filter: drop-shadow(0 20px 80px #ff6b0040);
}
label {
  margin-inline-end: 10px;
}
.hover-img-container div {
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: opacity .4s;
}
#view-cells:checked ~ .hover-img-container div {
  background: rgba(100,100,150,0.4);
  border: 1px solid;
  opacity: 1;
}
#more:checked ~ .hover-img-container {
  --rotation: 50deg;
}
              
            
!

JS

              
                
              
            
!
999px

Console