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

              
                <!--
 The key is to divide the image into multiple layers, each containing only gfx for a specific depth, see the individual images. Just brush off more and more of the deeper gfx for every layer. This, combined with the card rotation gives that subtle 3D effect.

The background and border are slightly rotated at the x-axis, so they cover the bottom and are behind the top of the layers.
-->
<div id="card" class="card">
	<div class="layer layer-top"></div>
	<div class="layer layer-middle"></div>
	<div class="layer layer-bottom"></div>
	<div class="layer layer-bg"></div>
	<div class="layer layer-edge"></div>
</div>

<a target="_blank" href="https://codepen.io/josfabre/pens/public" style="position: fixed; z-index: 100; left: 2em; top: 2em; font-family: Sans-Serif; color: lightgreen; font-size: 13px; text-decoration: none; text-transform: uppercase; padding: 0.5em 1em; border: 1px solid lightgreen; border-radius: 6px; opacity: 0.9; background-color: rgba(lightgreen, 0.2); ">All my pens</a>

<section style="position: fixed; left: 2em; bottom: 1em; font-family: 'Telefon', Sans-Serif; color:black; z-index:999;">
	<h3>Other pens</h3>
	<ul style="display:flex;list-style-type:none;margin: 0; padding: 0;">
		<li style="margin-right: 1em;"><a href="https://codepen.io/josfabre/pen/abReBvP" target="_blank" style="color:black;text-decoration:none;font-size:0.75rem;"><img style="border-radius: 8px;height: 80px; width: auto;box-shadow: 0 0 10px grey;" src="https://assets.codepen.io/439000/Screenshot+2023-06-07+at+08.39.48.png"><br>Real Slots Reels - Slot Machine</a></li>
		<li style="margin-right: 1em;"><a href="https://codepen.io/josfabre/pen/jOegyyJ" target="_blank" style="color:black;text-decoration:none;font-size:0.75rem;"><img style="border-radius: 8px;height: 80px; width: auto;box-shadow: 0 0 10px grey;" src="https://assets.codepen.io/439000/Screenshot+2023-06-07+at+08.56.26.png"><br>Magnifying Glass Newspaper</a></li>
</section>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Roboto:wght@900&display=swap");

* {
	transform-style: preserve-3d;
}

html,
body {
	width: 100%;
	height: 100%;
}

body {
	position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #444;
	perspective: 440px;
	overflow: hidden; // without this, 3D layering does not work!
	background-color: #f4d03f;
	background-image: linear-gradient(
		15deg,
		#225522 10%,
		#447744 45%,
		#220022 45.1%,
		#1a001a 90%
	);

	&::before {
		position: absolute;
		content: "she-hulk";
		height: 100%;
		width: 200%;
		font-size: 300px;
		letter-spacing: -18px;
		color: white;
		font-family: "Roboto", sans-serif;
		text-transform: uppercase;
		font-weight: bold;
		display: flex;
		justify-content: center;
		align-items: center;
		transform: rotate(15deg) translatey(-26px);
		color: #447744;
		filter: blur(1.5px);
	}

	&::after {
		position: absolute;
		content: "";
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		background-image: url(https://assets.codepen.io/439000/pattern.webp);
		background-size: cover;
		background-position: center;
		opacity: 0.05;
		mix-blend-mode: hard-light;
	}
}

.card {
	position: relative;
	width: 320px;
	height: 540px;
	margin: 4rem;

	@media screen and (max-width: 500px) {
		width: 240px;
		height: 540/320 * 240px;
	}

	.layer {
		width: 100%;
		height: 100%;
		position: absolute;
		background-repeat: no-repeat;
		background-position: bottom center;
		background-size: contain;

		&-top {
			transform: translate3d(0, 0, 6px);
			background-image: url(https://assets.codepen.io/439000/she1.webp);
		}

		&-middle {
			transform: translate3d(0, 0, 0);
			background-image: url(https://assets.codepen.io/439000/she2.webp);
		}

		&-bottom {
			transform: translate3d(0, 0, -6px);
			background-image: url(https://assets.codepen.io/439000/she3.webp);
		}

		&-bg {
			height: 98%;
			border-radius: 10px;
			box-shadow: 0 0 140px 2px rgba(lightgreen, 0.5);
			transform: translate3d(0, 30px, -25px) rotatex(4deg);

			&::before {
				position: absolute;
				content: "";
				left: 0;
				top: 0;
				bottom: 0;
				right: 0;
				background-color: #f4d03f;
				background-image: linear-gradient(-25deg, #448844 10%, #660066 90%);
			}
			&::after {
				position: absolute;
				content: "";
				left: 0;
				top: 0;
				bottom: 0;
				right: 0;
				background-image: url(https://assets.codepen.io/439000/giphy.gif);
				background-size: cover;
				mix-blend-mode: luminosity;
			}
		}
		&-edge {
			width: 86%;
			height: 88%;
			transform: translate3d(0, 34px, 5px) rotatex(3deg);
			border: 20px solid black;
			border-radius: 10px;
		}
	}
}

              
            
!

JS

              
                // translate mouse movement into 3D rotation
window.addEventListener("mousemove", (e) => {
	w = window.innerWidth;
	h = window.innerHeight;

	const rotx = 7 - e.pageY * (14 / h);
	const roty = -8 + e.pageX * (16 / w);

	document.getElementById(
		"card"
	).style.transform = `rotateY(${roty}deg) rotateX(${rotx}deg)`;
});

// translate touch movement into 3D rotation
window.addEventListener("touchmove", (e) => {
	w = window.innerWidth;
	h = window.innerHeight;

	const rotx = 7 - e.changedTouches[0].pageY * (14 / h);
	const roty = -10 + e.changedTouches[0].pageX * (20 / w);

	document.getElementById(
		"card"
	).style.transform = `rotateY(${roty}deg) rotateX(${rotx}deg)`;
});

              
            
!
999px

Console