A Pen by Mark Boots on CodePen.
Last active
May 1, 2024 01:33
-
-
Save mikepixeldev/694ab146e47bfdd2dde1b5410b278d10 to your computer and use it in GitHub Desktop.
Overlapping chars with shadow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 class="overlap overlap-front">Hello World</h1> | |
<h1 class="overlap overlap-back">Hello World</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const overlapEls = document.querySelectorAll(".overlap") || []; | |
overlapEls.forEach(el => { | |
const chars = [...el.textContent]; | |
el.innerHTML = ""; | |
chars.forEach((char,index) => { | |
const span = document.createElement("span"); | |
span.textContent = char; | |
span.style.setProperty("--index", index) | |
el.append(span) | |
}) | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap'); | |
html { | |
color-scheme: dark; | |
} | |
h1 { | |
text-align: center; | |
font-size: 20vmin; | |
font-family: 'Luckiest Guy', cursive; | |
text-transform: uppercase; | |
} | |
.overlap{ | |
--overlap: .15ch; | |
--shadow-offset: .1ch; | |
--shadow-blur: .2ch; | |
--shadow-color: black; | |
letter-spacing: calc(var(--overlap) * -1); | |
isolation: isolate; | |
} | |
.overlap-front { --mult: 1; } | |
.overlap-back { --mult: -1; } | |
.overlap>span { | |
position: relative; | |
z-index: calc(var(--index, 1) * var(--mult, 1)); | |
} | |
.overlap-front>span:not(:first-of-type), | |
.overlap-back>span:not(:last-of-type){ | |
text-shadow: | |
calc(var(--mult, 1) * var(--shadow-offset,0) * -1) 0 | |
var(--shadow-blur, 0) | |
var(--shadow-color, black); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment