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

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="butters">
			<div id="pants" class="butters__legs"></div>
			<div class="butters__feet">
				<div id="feet" class="butters__feet-left"></div>
				<div id="feet" class="butters__feet-right"></div>
			</div>
			<div class="butters__torso">
				<div id="shirt" class="butters__torso--shirt-bottom"></div>
				<div
					id="shirt"
					class="butters__torso--shirt-middle-square"
				></div>
				<div id="shirt" class="butters__torso--shirt-left-arm"></div>
				<div id="shirt" class="butters__torso--shirt-right-arm"></div>
				<div
					id="shirt"
					class="butters__torso--shirt-left-arm-two"
				></div>
				<div
					id="shirt"
					class="butters__torso--shirt-right-arm-two"
				></div>
				<div class="butters__torso--under-arm-left-line-one"></div>
				<div class="butters__torso--under-arm-left-line-two"></div>
				<div class="butters__torso--under-arm-right-line-one"></div>
				<div class="butters__torso--under-arm-right-line-two"></div>
				<div class="butters__torso--middle-line"></div>
			</div>
			<div id="skin" class="butters__face face">
				<div class="butters__face butters__face--left-eye"></div>
				<div class="butters__face butters__face--right-eye"></div>
				<div class="butters__face butters__face--left-eyeball"></div>
				<div class="butters__face butters__face--right-eyeball"></div>
				<div class="butters__face butters__face--left-eyebrow"></div>
				<div class="butters__face butters__face--right-eyebrow"></div>
				<div id="skin" class="butters__face butters__face--smile"></div>
			</div>
			<div class="butters__hands hands">
				<div
					id="skin"
					class="butter__hands butter__hands--left-hand"
				></div>
				<div
					id="skin"
					class="butter__hands butter__hands--left-thumb"
				></div>
				<div
					id="skin"
					class="butter__hands butter__hands--right-hand"
				></div>
				<div
					id="skin"
					class="butter__hands butter__hands--right-thumb"
				></div>
			</div>
			<div class="butters__hair">
				<div id="hairs" class="butters__hair--one"></div>
				<div id="hairs" class="butters__hair--two"></div>
				<div id="hairs" class="butters__hair--three"></div>
				<div id="hairs" class="butters__hair--four"></div>
				<div id="hairs" class="butters__hair--five"></div>
				<div id="hairs" class="butters__hair--six"></div>
			</div>
		</div>
		<div id="about" class="about">CSS Art by Cooper</div>

		<div class="fabuliser-container">
			<button class="rgbButton" id="rgbButton">Fabuliser</button>
			<div id="rgb" class="rgb">
				<select name="item-select" id="item-select">
					<option id="item-select" value="">
						Select an item to fabulise
					</option>
					<option id="item-select" value="skin">Skin</option>
					<option id="item-select" value="hair">Hair</option>
					<option id="item-select" value="shirt">Shirt</option>
					<option id="item-select" value="pants">Pants</option>
					<option id="item-select" value="shoes">Shoes</option>
					<option id="item-select" value="background">
						Background
					</option>
				</select>
				<div id="spectrum-wrapper" class="spectrum-wrapper">
					<div id="spectrum-wrapper" class="spectrum-layer"></div>
					<div id="spectrum-wrapper" class="saturation-white"></div>
					<div id="spectrum-wrapper" class="saturation-black"></div>
				</div>
			</div>
		</div>
              
            
!

CSS

              
                /* Universal Box Sizing w. Inheritance*/
html {
	box-sizing: border-box;
}
*,
*::before,
*::after {
	box-sizing: inherit;
}
:root {
	--bg: rgb(253, 200, 209);
	--size: 80;
	/*  Using viewport units  https://css-tricks.com/simple-little-use-case-vmin/ */
	--unit: calc((var(--size) / 1063) * 1vmin);
	--skin: rgb(255, 221, 186);
	--eye-white: rgb(255, 255, 255);
	--hair: rgb(255, 255, 0);
	--shirt: rgb(74, 222, 191);
	--shorts: rgb(30, 95, 73);
	--black: rgb(0, 0, 0);
}

body {
	background-color: var(--bg);
	min-height: 100vh;
	font-family: "Quicksand", sans-serif;
	font-size: 1.5rem;
	overflow: hidden;
}

.about {
	position: absolute;
	top: 0px;
	right: 5px;
	/* transform: rotate(90deg); */
}

/* Butters intrinsic values => w 752 + h 1063 */
/* Intrinsic height can be located in the image location of the dev tools */

/* Whole container */
.butters {
	/* as the height and width of the image and drawing are the same they can be placed together */
	height: calc(1063 * var(--unit));
	width: calc(752 * var(--unit));

	/* Aligning the image in the centre */
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
}

/* Face Container */
.face {
	background-color: var(--skin);
	height: 62.5%;
	width: 88%;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-48.5%, -66%);
	border-radius: 51% 50% 50% 50%;
}
/* Face Parts */
.butters__face--left-eye {
	background-color: var(--eye-white);
	height: 32.5%;
	width: 28%;
	position: absolute;
	top: 39%;
	left: 22%;
	border-radius: 90% 55% 90% 55%;
	/*             tl  tr  br  bl */
}
.butters__face--right-eye {
	background-color: var(--eye-white);
	height: 32.5%;
	width: 28%;
	position: absolute;
	top: 39%;
	left: 49.5%;
	border-radius: 55% 90% 55% 90%;
}
.butters__face--left-eyeball {
	background-color: var(--black);
	height: 3.6%;
	width: 3.6%;
	position: absolute;
	top: 54%;
	left: 38.8%;
	border-radius: 50%;
}
.butters__face--right-eyeball {
	background-color: var(--black);
	height: 3.6%;
	width: 3.6%;
	position: absolute;
	top: 54%;
	left: 55%;
	border-radius: 50%;
}
.butters__face--right-eyebrow {
	border: 0.5px var(--black) solid;
	width: 20%;
	position: absolute;
	top: 38.7%;
	left: 16.8%;
	transform: rotate(139deg);
}
.butters__face--left-eyebrow {
	border: 0.5px var(--black) solid;
	width: 20%;
	position: absolute;
	top: 38.9%;
	left: 64%;
	transform: rotate(39.5deg);
}
.butters__face--smile {
	border: 0.5px var(--black) solid;
	border-radius: 50%;
	height: 30%;
	width: 30%;
	position: absolute;
	top: 55.7%;
	left: 34.5%;
	clip-path: inset(95% 0% 0% 0);
}

/* Hair Container */
.butters__hair {
	position: absolute;
	height: 26.5%;
	width: 72%;
	left: 49%;
	top: 1%;
	transform: translate(-50%, 0);
}
/* Hair Parts */
.butters__hair--one {
	background-color: var(--hair);
	position: absolute;
	height: 110%;
	width: 100%;
	top: 30%;
	left: 35%;
	transform: translate(-50%, -50%);

	clip-path: polygon(32% 23%, 46% 27%, 67% 43%, 43% 49%, 35% 26%);
}
.butters__hair--two {
	background-color: var(--hair);
	position: absolute;
	height: 100%;
	width: 100%;
	top: 26.5%;
	left: 41%;
	transform: translate(-50%, -50%);

	clip-path: polygon(89% 22%, 42% 51%, 82% 47%);
}
.butters__hair--three {
	background-color: var(--hair);
	position: absolute;
	height: 100%;
	width: 100%;
	top: 46.5%;
	left: 51%;
	transform: translate(-50%, -50%);

	clip-path: polygon(72% 23%, 86% 34%, 101% 56%, 82% 46%, 26% 49%, 27% 29%);
}
.butters__hair--four {
	background-color: var(--hair);
	position: absolute;
	height: 100%;
	width: 100%;
	top: 71.5%;
	left: 55.5%;
	transform: translate(-50%, -50%);

	clip-path: polygon(
		76% 21%,
		87% 48%,
		93% 80%,
		87% 69%,
		65% 47%,
		51% 37%,
		21% 23%
	);
}
.butters__hair--five {
	background-color: var(--hair);
	position: absolute;
	height: 101%;
	width: 59%;
	top: 83.5%;
	left: 38.5%;
	transform: translate(-50%, -50%);

	clip-path: polygon(
		83% 18%,
		66% 35%,
		45% 51%,
		28% 60%,
		20% 64%,
		15% 66%,
		38% 20%
	);
}
.butters__hair--six {
	background-color: var(--hair);
	position: absolute;
	height: 114%;
	width: 71%;
	top: 65%;
	left: 31.5%;
	transform: translate(-50%, -50%);

	clip-path: polygon(
		42% 18%,
		50% 14%,
		69% 43%,
		28% 49%,
		4% 53%,
		19% 38%,
		35% 21%
	);
}

/* Hands Container */
.butters__hands {
	position: absolute;
	height: 10.5%;
	width: 77.5%;
	top: 87%;
	left: 50.5%;
	transform: translate(-50%, -50%);
}
/* Hands Parts */
.butter__hands--left-hand {
	background-color: var(--skin);
	position: absolute;
	height: 84.5%;
	width: 17.5%;
	top: 45%;
	left: 9%;
	transform: translate(-50%, -50%);
	border-radius: 50% 50%;
}
.butter__hands--left-thumb {
	background-color: var(--skin);
	border: solid 1px var(--black);
	position: absolute;
	height: 47%;
	width: 9%;
	top: 35%;
	left: 15%;
	transform: translate(-50%, -50%);
	border-radius: 50% 50%;
}
.butter__hands--right-hand {
	background-color: var(--skin);
	position: absolute;
	height: 84.5%;
	width: 17.5%;
	top: 50%;
	left: 91.5%;
	transform: translate(-50%, -50%);
	border-radius: 50% 50%;
}
.butter__hands--right-thumb {
	background-color: var(--skin);
	border: solid 1px var(--black);
	position: absolute;
	height: 47%;
	width: 9%;
	top: 35%;
	left: 86%;
	transform: translate(-50%, -50%);
	border-radius: 50% 50%;
}
.butters__torso {
	position: absolute;
	height: 30%;
	width: 77%;
	top: 79%;
	left: 51%;
	transform: translate(-50%, -50%);
}
.butters__torso--shirt-bottom {
	background-color: var(--shirt);
	position: absolute;
	height: 30%;
	width: 83%;
	top: 85.4%;
	left: 51.5%;
	transform: translate(-50%, -50%);
	border-radius: 50% 50%;
}
.butters__torso--shirt-middle-square {
	background-color: var(--shirt);
	position: absolute;
	height: 99%;
	width: 70%;
	top: 39.4%;
	left: 50.5%;
	transform: translate(-50%, -50%);
}
.butters__torso--shirt-left-arm {
	background-color: var(--shirt);
	height: 115.5%;
	width: 28%;
	position: absolute;
	top: -5%;
	left: 2%;
	border-radius: 151% 55% 94% 55%;
	clip-path: inset(0% 0 25% 0);
}
.butters__torso--shirt-left-arm-two {
	background-color: var(--shirt);
	height: 50%;
	width: 12%;
	position: absolute;
	top: 30%;
	left: 2%;
	transform: rotate(16deg);
	clip-path: inset(12% 0 10% 0);
	border-radius: 0% 0% 0% 50%;
}
.butters__torso--shirt-right-arm {
	background-color: var(--shirt);
	height: 82%;
	width: 17%;
	position: absolute;
	top: -3%;
	left: 79%;
	transform: rotate(159deg);

	border-radius: 55% 60% 45% 70% / 40% 60% 45% 70%;
}
.butters__torso--shirt-right-arm-two {
	background-color: var(--shirt);
	height: 37%;
	width: 29%;
	position: absolute;
	top: 11%;
	left: 68.5%;
	transform: rotate(62deg);
	clip-path: inset(0% 31% 0% 0%);
}
.butters__torso--under-arm-left-line-one {
	border: 1px var(--black) solid;
	width: 11%;
	position: absolute;
	top: 60.7%;
	left: 8.9%;
	transform: rotate(105deg);
}
.butters__torso--under-arm-left-line-two {
	border: 1px var(--black) solid;
	width: 6.1%;
	position: absolute;
	top: 46.4%;
	left: 14.3%;
	transform: rotate(120deg);
}
.butters__torso--under-arm-right-line-one {
	border: 1px var(--black) solid;
	width: 12%;
	position: absolute;
	top: 63.7%;
	left: 80.5%;
	transform: rotate(74deg);
}
.butters__torso--under-arm-right-line-two {
	border: 1px var(--black) solid;
	width: 6.4%;
	position: absolute;
	top: 48.4%;
	left: 80%;
	transform: rotate(60deg);
}
.butters__torso--middle-line {
	border: 1px var(--black) solid;
	height: 76%;
	position: absolute;
	top: 23%;
	left: 50%;
}

/* Legs Container (one part) */
.butters__legs {
	background-color: var(--shorts);
	height: 10%;
	width: 60%;
	position: absolute;
	top: 88.7%;
	left: 21.5%;
}

/* Feet Container */
.butters__feet {
	/* background-color: hsla(0, 100%, 50%, 0.2); */
	position: absolute;
	height: 3%;
	width: 69%;
	top: 98%;
	left: 50%;
	transform: translate(-50%, -50%);
}
/* Feet Parts */
.butters__feet-left {
	/* background-color: hsla(0, 100%, 50%, 0.2); */
	background-color: var(--black);
	position: absolute;
	height: 295%;
	width: 61%;
	top: 13%;
	left: -3%;
	border-radius: 50% 50%;
	clip-path: inset(0% 0% 74% 0%);
}
.butters__feet-right {
	/* background-color: hsla(0, 100%, 50%, 0.2); */
	background-color: var(--black);
	position: absolute;
	height: 295%;
	width: 61%;
	top: 13%;
	left: 41%;
	border-radius: 50% 50%;
	clip-path: inset(0% 0% 74% 0%);
}

/* to cut pieces to bits, use clip path */
/* clip-path: inset(0 0 0 0) */

/* for more refinement with boarder radius use the divide to get points in each corner rather than one */
/* border-radius: 55% 60% 45% 70% / 40% 60% 45% 70%; */

/* to create the trace background colour */
/* background-color: hsla(0, 100%, 50%, 0.2); */

/* CSS selector for RGB */
.rgb {
	display: none;
}
.fabuliser-container {
	width: 400px;
	display: flex;
}
#item-select {
	width: 210px;
	height: 40px;
	border: none;
	background-color: black;
	color: white;
	font-family: "Quicksand", sans-serif;
	font-size: 1rem;
}
.rgbButton {
	width: 100px;
	height: 40px;
	border: none;
	background-color: black;
	color: white;
	font-family: "Quicksand", sans-serif;
	font-size: 1rem;
}
.spectrum-wrapper {
	position: absolute;
	cursor: crosshair;
	bottom: 1%;
	left: 1%;
	width: 360px;
	height: 120px;
	user-select: none;
}
.spectrum-layer {
	height: 100%;
	width: 100%;
	background: linear-gradient(
		to right,
		rgb(255 0 0),
		rgb(255 255 0),
		rgb(0 255 0),
		rgb(0 255 255),
		rgb(0 0 255),
		rgb(255 0 255),
		rgb(255 0 0)
	);
}

.saturation-white {
	background: -webkit-linear-gradient(to top, rgba(255, 255, 255, 0), #fff);
	background: linear-gradient(to top, rgba(255, 255, 255, 0), #fff);
	position: absolute;
	width: 100%;
	height: 60px;
	top: 0px;
	right: 0px;
	bottom: 60px;
	left: 0px;
}

.saturation-black {
	background: -webkit-linear-gradient(to bottom, rgba(0, 0, 0, 0), #000);
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0), #000);
	position: absolute;
	width: 100%;
	height: 60px;
	top: 60px;
	right: 0px;
	bottom: 0px;
	left: 0px;
}

              
            
!

JS

              
                const showButton = document.getElementById("rgbButton");
const rgbSelector = document.getElementById("rgb");
const articleSelector = document.getElementById("item-select");
const about = document.getElementById("about");
const getSpectrumWrapper = () => document.querySelector(".spectrum-wrapper");

// Clothing element selectors to change image colours
const hairs = document.querySelectorAll("#hairs");
const shirt = document.querySelectorAll("#shirt");
const skin = document.querySelectorAll("#skin");
const pants = document.querySelectorAll("#pants");
const feet = document.querySelectorAll("#feet");

// Toggle the RGB selector
showButton.addEventListener("click", () => {
	if (rgbSelector.style.display == "block") {
		rgbSelector.style.display = "none";
		about.style.display = "block";
	} else {
		rgbSelector.style.display = "block";
		about.style.display = "none";
	}
});

articleSelector.addEventListener("change", (e) => {
	document.getElementById("selectedItem").innerHTML = articleSelector.value;
});

const spectrumRanges = [
	{ from: [255, 0, 0], to: [255, 255, 0] },
	{ from: [255, 255, 0], to: [0, 255, 0] },
	{ from: [0, 255, 0], to: [0, 255, 255] },
	{ from: [0, 255, 255], to: [0, 0, 255] },
	{ from: [0, 0, 255], to: [255, 0, 255] },
	{ from: [255, 0, 255], to: [255, 0, 0] },
];

const findColorValue = (from, to, leftDistRatio) => {
	return Math.round(from + (to - from) * leftDistRatio);
};

const findRgbFromMousePosition = (event) => {
	const { left, width } = getSpectrumWrapper().getBoundingClientRect();
	const leftDistance = Math.min(Math.max(event.clientX - left, 0), width - 1);
	const rangeWidth = width / spectrumRanges.length;
	const includedRange = Math.floor(leftDistance / rangeWidth);
	const leftDistRatio = ((leftDistance % rangeWidth) / rangeWidth).toFixed(2);
	const { from, to } = spectrumRanges[includedRange];
	return {
		r: findColorValue(from[0], to[0], leftDistRatio),
		g: findColorValue(from[1], to[1], leftDistRatio),
		b: findColorValue(from[2], to[2], leftDistRatio),
	};
};

const darken = (color, ratio) => Math.round((1 - ratio) * color);
const whiten = (color, ratio) => Math.round(color + (255 - color) * ratio);
const adjustSaturation = ({ r, g, b }) => (ratio, adjustmentFn) => {
	return {
		r: adjustmentFn(r, ratio),
		g: adjustmentFn(g, ratio),
		b: adjustmentFn(b, ratio),
	};
};

const saturate = (rgb, e) => {
	const { top, height } = getSpectrumWrapper().getBoundingClientRect();
	const topDistance = Math.min(Math.max(e.clientY - top, 0), height);
	const topDistRatio = (topDistance / height).toFixed(2);
	if (topDistRatio > 0.5) {
		const darknessRatio = (topDistRatio - 0.5) / 0.5;
		return adjustSaturation(rgb)(darknessRatio, darken);
	}
	if (topDistRatio < 0.5) {
		const whitenessRatio = (0.5 - topDistRatio) / 0.5;
		return adjustSaturation(rgb)(whitenessRatio, whiten);
	}
	return rgb;
};

document.addEventListener(
	"click",
	function (e) {
		// If the clicked element doesn't have the right selector, bail
		e.preventDefault();

		if (!e.target.matches("#spectrum-wrapper")) return;

		const rgb = findRgbFromMousePosition(e);
		const { r, g, b } = saturate(rgb, e);

		if (articleSelector.value == "skin") {
			changeSkin(r, g, b);
		}
		if (articleSelector.value == "hair") {
			changeHair(r, g, b);
		}
		if (articleSelector.value == "shirt") {
			changeShirt(r, g, b);
		}
		if (articleSelector.value == "pants") {
			changePants(r, g, b);
		}
		if (articleSelector.value == "shoes") {
			changeFeet(r, g, b);
		}
		if (articleSelector.value == "background") {
			document.body.style.background =
				"rgb(" + r + "," + g + "," + b + ")";
		}
	},
	false
);

const changeHair = (r, g, b) => {
	hairs.forEach((h) => {
		h.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
	});
};

const changeShirt = (r, g, b) => {
	shirt.forEach((s) => {
		s.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
	});
};

const changeSkin = (r, g, b) => {
	skin.forEach((s) => {
		s.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
	});
};

const changePants = (r, g, b) => {
	pants.forEach((p) => {
		p.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
	});
};
const changeFeet = (r, g, b) => {
	feet.forEach((f) => {
		f.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
	});
};

              
            
!
999px

Console