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

              
                <button class="fc spawned" type="button">
	<div class="fc-part left"></div>
	<div class="fc-part right"></div>
	<div class="fc-crumbs">
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
		<div class="fc-crumb"></div>
	</div>
	<div class="fc-fortune">
		<p class="fc-fortune-text">No fortune</p>
		<p class="fc-lucky-numbers">Lucky Numbers <span>?, ?, ?, ?, ?, ?</span></p>
	</div>
</button>
              
            
!

CSS

              
                * {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
body, button {
	font-size: 16px;
	line-height: 1.5;
}
body {
	background: #D00018;
}
button {
	cursor: pointer;
}
/* Cookie */
.fc {
	background: transparent;
	display: block;
	margin: 4.5em auto 0 auto;
	position: relative;
	width: 20em;
	height: 17em;
}
.fc:focus {
	outline: transparent;
}
.fc-part, .fc-crumbs, .fc-crumb, .fc-fortune {
	position: absolute;
	top: 0;
}
.fc-part, .fc-crumb {
	background: currentColor;
	color: #efaa5d;
}
.fc-part {
	width: 8em;
	height: 18em;
	z-index: 2;
}
.left {
	border-radius: 7em 1em 1em 7em / 50%;
	box-shadow:
		0.5em 0 0 inset,
		0.5em 0.2em 0 inset,
		1em 0.2em 0 #fff6 inset,
		-0.75em 0 0 #0002 inset;
	clip-path: polygon(0% 0%, 68% 0%, 100% 30%, 100% 100%, 0% 100%);
	-webkit-clip-path: polygon(0% 0%, 68% 0%, 100% 30%, 100% 100%, 0% 100%);
	left: calc(50% - 5.4em);
	transform: rotate(25deg);
	transform-origin: 68% 0;
}
.right {
	border-radius: 1em 7em 7em 1em / 50%;
	box-shadow:
		-0.5em 0 0 inset,
		-0.5em 0.2em 0 inset,
		-1em 0.2em 0 #fff6 inset,
		0.75em 0 0 #0002 inset;
	clip-path: polygon(0% 30%, 32% 0%, 100% 0, 100% 100%, 0% 100%);
	-webkit-clip-path: polygon(0% 30%, 32% 0%, 100% 0, 100% 100%, 0% 100%);
	right: calc(50% - 5.4em);
	transform: rotate(-25deg);
	transform-origin: 32% 0;
}
.fc-crumbs {
	left: calc(50% - 0.4em);
	width: 0.8em;
	height: 6em;
	z-index: 1;
}
.fc-crumb {
	border-radius: 50%;
	width: 0.5em;
	height: 0.5em;
}
.fc-crumb:nth-child(1) {
	top: 4%;
	left: 15%;
}
.fc-crumb:nth-child(2) {
	top: 20%;
	right: 15%;
}
.fc-crumb:nth-child(3) {
	top: 30%;
	left: 25%;
}
.fc-crumb:nth-child(4) {
	top: 45%;
	right: 25%;
}
.fc-crumb:nth-child(5) {
	top: 55%;
	left: 5%;
}
.fc-crumb:nth-child(6) {
	top: 65%;
	right: 5%;
}
.fc-crumb:nth-child(7) {
	top: 75%;
	left: 30%;
}
.fc-crumb:nth-child(8) {
	top: 90%;
	right: 35%;
}

/* Fortune */
.fc-fortune {
	background:
		linear-gradient(#fff0 .75em,#fff 0 5.25em,#fff0 0),
		linear-gradient(90deg,currentColor 3em,#fff 0 25.25em,currentColor 0);
	color: #00c;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0.75em 1.5em 0.75em 3.75em;
	text-align: center;
	width: 26em;
	height: 6em;
	left: 0;
	transform: scale(0,1);
	transform-origin: 50% 32%;
}
.fc-fortune-text {
	font-family: serif;
}
.fc-lucky-numbers {
	font-family: sans-serif;
}

/* Animation States */
.spawned {
	animation: popIn 0.3s linear;
}
.opened {
	width: 26em;
	height: 6em;
}
.opened .left {
	animation: breakLeft 0.7s ease-in forwards;
}
.opened .right {
	animation: breakRight 0.7s ease-in forwards;
}
.opened .fc-crumbs {
	animation: fallOut 0.7s ease-in forwards;
}
.opened .fc-fortune {
	animation: foldOut 0.7s ease-in forwards;
}

/* Animations */
@keyframes popIn {
	from {
		transform: scale(0);
	}
	75% {
		transform: scale(1.1);
	}
	to {
		transform: scale(1);
	}
}
@keyframes breakLeft {
	from {
		transform: translateX(0) rotate(25deg);
	}
	30%, 40% {
		transform: translateX(0) rotate(55deg);
	}
	70%, 80% {
		opacity: 1;
		transform: translateX(-14em) rotate(50deg);
	}
	to {
		opacity: 0;
		transform: translateX(-14em) rotate(50deg);
	}
}
@keyframes breakRight {
	from {
		transform: translateX(0) rotate(-25deg);
	}
	30%, 40% {
		transform: translateX(0) rotate(-55deg);
	}
	70%, 80% {
		opacity: 1;
		transform: translateX(14em) rotate(-50deg);
	}
	to {
		opacity: 0;
		transform: translateX(14em) rotate(-50deg);
	}
}
@keyframes fallOut {
	from {
		left: calc(50% - 0.4em);
		width: 0.8em;
		transform: translateY(0);
	}
	30% {
		opacity: 1;
	}
	60%, to {
		opacity: 0;
		left: calc(50% - 3em);
		width: 6em;
		transform: translateY(24em);
	}
}
@keyframes foldOut {
	from {
		transform: scale(0.23,0.7);
	}
	30%, 40% {
		transform: scale(0.5,0.7);
	}
	69% {
		transform: scale(1,0.7);
	}
	74%, to {
		transform: scale(1,1);
	}
}
              
            
!

JS

              
                addEventListener("load",app);
function app() {
	class Fortune {
		constructor(fortuneList) {
			this.text = !fortuneList ? "No fortune" : fortuneList[~~(Math.random() * fortuneList.length)];
			this.luckyNumbers = [];
			this.drawLuckyNumbers();
		}
		drawLuckyNumbers() {
			let maxDraws = 6,
				draws = maxDraws,
				maxNumber = 99,
				numberPool = [];

			// create number pool
			while (maxNumber--) {
				numberPool.unshift(maxNumber + 1);
			}
			// draw from pool, populate the lucky numbers
			while (draws--) {
				let drawn = ~~(Math.random() * numberPool.length);
				this.luckyNumbers.push(numberPool[drawn]);
				numberPool.splice(drawn,1);
			}
		}
	}

	var fcBtn = document.querySelector("button"),
		fortuneText = document.querySelector(".fc-fortune-text"),
		fortuneLuckyNumbers = document.querySelector(".fc-lucky-numbers span"),
		fortuneList = [
			"Did you know that fortune cookies aren’t even Chinese? They’re made by Americans, based on a Japanese recipe.",
			"You have an ability to sense and know higher truth.",
			"Excellent time to become a missing person.",
			"Don’t look back, the lemmings are gaining on you.",
			"You look tired.",
			"Chess tonight.",
			"Don’t feed the bats tonight.",
			"Your boss is a few sandwiches short of a picnic.",
			"You will forget that you ever knew me.",
			"Future looks spotty. You will spill soup in late evening.",
			"You have the capacity to learn from mistakes. You’ll learn a lot today.",
			"A vivid and creative mind characterizes you.",
			"If you think last Tuesday was a drag, wait till you see what happens tomorrow!",
			"You will be attacked next Wednesday at 3:15 P.M. by six samurai sword wielding purple fish glued to Harley-Davidson motorcycles.",
			"There was a phone call for you.",
			"Are you making all this up as you go along?",
			"Don’t plan any hasty moves. You’ll be evicted soon anyway.",
			"Advancement in position.",
			"You’re ugly and your mother dresses you funny.",
			"Be careful! Is it classified?"
		],
		fortune = new Fortune(),

		getFortune = function(){
			fortune = new Fortune(fortuneList);
			fortuneText.innerHTML = fortune.text;
			fortuneLuckyNumbers.innerHTML = fortune.luckyNumbers.join(", ");
		},
		nextState = function(){
			let elClass = this.classList,
				spawned = "spawned",
				opened = "opened";

			// open cookie
			if (elClass.contains(spawned)) {
				elClass.remove(spawned);
				elClass.add(opened);

			// new cookie
			} else {
				elClass.remove(opened);
				elClass.add(spawned);
				getFortune();
			}
		};
	
	getFortune();
	fcBtn.addEventListener("click",nextState);
}
              
            
!
999px

Console