Loading video...

Video Failed to Load

Go Home

Little CSS Christmas tree for the holidays ๐ŸŽ„ Powered by CSS custom properties ๐Ÿ’ช ~100 lines of CSS The trick is in the animation-delay โœจ For example; <div class=๐Ÿ”ด style="--index: 2;"> .๐Ÿ”ด { animation-delay: calc(var(--index) * -0.2s); } CodePen.IO link below! ๐Ÿ‘‡

374,796 views โ€ข 3 years ago โ€ขvia X (Twitter)

10 Comments

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

Here's that @CodePen link! ๐ŸŽ…๐Ÿป Have a play with the custom properties set on :root to see how the behavior changes ๐Ÿค“ You could make the CSS smaller, add layers, more baubles, etc. Rustled this one up over breakfast after seeing something in the mall ๐Ÿ˜…

James Q Quick's profile picture
James Q Quick3 years ago

@CodePen Holy mother of Christmas. You never cease to amaze me!

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

@CodePen "Mother of Christmas" ๐Ÿ˜… Happy Holidays my friend! ๐ŸŽ„

Amos Gyamfi's profile picture
Amos Gyamfi3 years ago

@TSplone @CodePen Nice, I will make a SwiftUI version

Luca Lanziani's profile picture
Luca Lanziani3 years ago

@CodePen I don't know if you did it in purpose but you have an interesting effect there. Try asking people in which direction are the lights rotating ๐Ÿ˜๐ŸŽ„

Sulamita Ivanov's profile picture
Sulamita Ivanov3 years ago

@CodePen This is insane ๐Ÿ˜ณ๐Ÿ‘๐Ÿผ

Adrien's profile picture
Adrien3 years ago

@smashingmag @CodePen the "over breakfast" hurt my soul :(

rinnegan's profile picture
rinnegan3 years ago

@CodePen Hi there! What a great CSS Christmas tree! I love seeing how creative people can get with the power of CSS and custom properties. Thanks for sharing your amazing work and making this holiday season a little brighter!

filip's profile picture
filip3 years ago

@haroldao_ @CodePen really cool, makes me wanna try this ๐Ÿ‘

Damien Toscano ๐Ÿ’ปโœจ's profile picture
Damien Toscano ๐Ÿ’ปโœจ2 years ago

@CodePen I remember my first algorithm course at university 9 years ago, I had to make a christmas three with loops and conditions ๐Ÿ˜Š

Related Videos

CSS Tip! ๐ŸŽ  You can create a responsive infinite marquee animation with container queries and no duplicate items ๐Ÿค™ li{ animation: slide; } @โ€‹keyframes slide { to { translate: 0% calc(var(--i) * -100%);}} The trick is animating the items, not the list ๐Ÿ˜Ž More tricks ๐Ÿ‘‡ To get this one working, you need to animate the items and not the list (Watch the video first?). Each item needs to know its row index (--i) in the list and the parent needs to know how many rows are in the list: ul { --count: 12; } li:nth-of-type(1), li:nth-of-type(2) { --i: 0; } li:nth-of-type(3), li:nth-of-type(4) { --i: 1; } Once you have that, translate each item based on its row index in the list li { translate: 0% calc((var(--count) - var(--i)) * 100%); } Now for the animation. The key here is that each row has an animation-delay calculated from its index (--i). That number is offset to make it negative so the animation start is offset โœจ ul { --duration: 10s; } li { --delay: calc((var(--duration) / var(--count)) * (var(--i) - 8)); animation: slide var(--duration) var(--delay) infinite linear; } Make sure to wrap that animation in: @โ€‹media (prefers-reduced-motion: no-preference) { ... } Lastly, the fun parts! ๐Ÿค“ To create the "vignette" mask. Use a layered mask on the container ๐Ÿ˜ท .scene { --buff: 3rem; height: 100%; width: 100%; mask: linear-gradient(transparent, white var(--buff) calc(100% - var(--buff)), transparent), linear-gradient(90deg, transparent, white var(--buff) calc(100% - var(--buff)), transparent); mask-composite: intersect; } To create the 3D skewed effect, use a chained transform (Try toggling it in the demo โšก๏ธ): .grid { transform: rotateX(20deg) rotateZ(-20deg) skewX(20deg); } As for the responsive part, use container queries! ๐Ÿ”ฅ article { container-type: inline-size; } When the article (card) is narrower than 400px update the grid and animation settings ๐Ÿค™ Double the rows means double the duration! @โ€‹container (width < 400px) { .grid { --count: 12; grid-template-columns: 1fr; } li:nth-of-type(1) { --i: 0; } li:nth-of-type(2) { --i: 1; } li:nth-of-type(3) { --i: 2; } li:nth-of-type(4) { --i: 3; } li { --duration: 20s; } } CSS has the magic to be able to update those animations at runtime based on your custom property values ๐Ÿ˜Ž An added bonus in this demo is that it doesn't require any JavaScript at all, for any of it ๐Ÿคฏ We can use CSS :has() for those toggles that update the styles, even the theme toggle! ๐Ÿซถ Any questions, let me know! Make sure to check out the video. Will do a walkthrough one to follow-up ๐Ÿค™ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

542,234 views โ€ข 2 years ago

CSS Tip! ๐Ÿ’ซ You can create this responsive perspective warp animation with 3D CSS and container queries โœจ (Video reveals trick ๐Ÿ‘€) .warp { container-type: size; perspective: 100px; transform-style: preserve-3d; resize: both; overflow: hidden; } Couple of tricks in this one ๐Ÿค“ The main idea is to create a tunnel (an open-ended cube). On each side of the tunnel, use linear-gradient to create the grid lines โœจ .side { background: linear-gradient(#โ€‹fff 0 1px, transparent 1px 5%) 50% 0 / 5% 5%, linear-gradient(90deg, #โ€‹fff 0 1px, transparent 1px 5%) 50% 50% / 5% 5%; } To position each side, you rotate on the x-axis by 90deg. Each side would become invisible at this point. So you give the scene perspective ๐Ÿ˜‰ .warp__side--top { width: 100cqi; height: 100cqmax; transform-origin: 50% 0%; transform: rotateX(-90deg); } The cool part here is that you want to make each side the same height. But the container is responsive. So you can use a container query and make sure each side is 100cqmax tall ๐Ÿซถ Then the "beams". Each side contains "beams". They have different colors, sizes, and positions, and move at different speeds โšก๏ธ We can control that through scoped custom properties. .beam { width: 5%; position: absolute; top: 0; left: calc(var(--x, 0) * 5%); aspect-ratio: 1 / 2; background: linear-gradient( hsl(var(--hue) 80% 60%), transparent ); translate: 0 100%; animation: warp calc(var(--speed, 0) * 1s) calc(var(--delay, 0) * -1s) infinite linear; } The magic here is though that a beam's animation is as basic as translating it from the top of the side to the bottom. And you can get that distance with a container query again ๐Ÿ”ฅ @โ€‹keyframes warp { 0% { translate: -50% 100cqmax; } 100% { translate: -50% -100%; } } And that is pretty much it! A cool warp animation effect using 3D CSS and container queries โšก๏ธ If you have any questions, let me know แต”แดฅแต” CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

187,474 views โ€ข 2 years ago