Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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,621 Aufrufe • vor 3 Jahren •via X (Twitter)

10 Kommentare

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

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 😅

Profilbild von James Q Quick
James Q Quickvor 3 Jahren

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

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

@CodePen "Mother of Christmas" 😅 Happy Holidays my friend! 🎄

Profilbild von Amos Gyamfi
Amos Gyamfivor 3 Jahren

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

Profilbild von Luca Lanziani
Luca Lanzianivor 3 Jahren

@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 😁🎄

Profilbild von Sulamita Ivanov
Sulamita Ivanovvor 3 Jahren

@CodePen This is insane 😳👏🏼

Profilbild von Adrien
Adrienvor 3 Jahren

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

Profilbild von rinnegan
rinneganvor 3 Jahren

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

Profilbild von filip
filipvor 3 Jahren

@haroldao_ @CodePen really cool, makes me wanna try this 👏

Profilbild von Damien Toscano 💻✨
Damien Toscano 💻✨vor 2 Jahren

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

Ähnliche 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 ʕ•ᴥ•ʔ

541,845 Aufrufe • vor 2 Jahren