Загрузка видео...

Не удалось загрузить видео

На главную

CSS container query for when an element is stuck with position: sticky 🔥 nav { container-type: scroll-state; } @​container scroll-state(stuck: top) { .nav__content { --expand: 1; } } use custom property to morph CTA into a nav bar with transitioned grid-template-columns 😎

88,665 просмотров • 1 год назад •via X (Twitter)

Комментарии: 8

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈1 год назад

like seeing these and want to learn more about how to build awesome UIs for the web? Check out my newsletter, "The Craft of UI" (Thank you for all the support, each issue, each sub, etc. gets us one step closer to courses 🤙) 👉

Фото профиля daniel
daniel1 год назад

could you share the codepen please <3

Фото профиля Mohamed Mansour
Mohamed Mansour1 год назад

New article on substack! We are using css container queries for search experiences, where search input rendered in center of the page, and when you scroll more than the page height, it is fixed to the top (no js). Very powerful!

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈1 год назад

as in you wrote one? or you want to see one? 🧐 this demo in particular was an interesting revisit because there's gonna be like 3 or 4 ways to do this actually think turning this into a full size search input could be cool kinda reminds me of

Фото профиля Francis Perron ⚡️
Francis Perron ⚡️1 год назад

Are you a team to come up with new ideas and css properties I never heard of before, or is it all you?

Фото профиля Chris Smith
Chris Smith1 год назад

What is the browser support for :stuck?

Фото профиля teriyaki
teriyaki1 год назад

Nitip

Фото профиля Matthias Martin
Matthias Martin1 год назад

That is awesome, I always had to do this with JS. And I’m trying to use as much CSS as possible in favor of JS.

Похожие видео

CSS Tip! 🍬 You can create a CSS-only sticky CTA using position: sticky or scroll-driven animations 🤙 .cta { position: sticky; margin-top: 110vh; bottom: 2rem; /* 👈 Stick! */ } This is one way 👀 This first way relies on you setting a layout on the body and putting the CTA in a zero-space part of the layout body { display: grid; grid-template-columns: auto 0; } The children of the body are an element with your content and then the CTA. You could also use display:flex too. .content { flex: 1 0 100%; } .cta { place-self: end; } As you scroll the body, the CTA comes into view and sticks in position 🙌 That's one way. If you want to take it further and do something like flip between showing or not, maybe scale it up, or add some special easing, etc. an animation is another way 📜 First, change the styles for your CTA. Note the translate property that's powered by a custom property .cta { position: fixed; bottom: 2rem; right: 2rem; translate: 0 calc(20vh - (var(--show) * 20vh)); transition: translate 0.875s var(--elastic); } Next you need a custom property that you're going to animate @​property --show { inherits: true; initial-value: 0; syntax: ' '; } Lastly, you animate this value on the body. As the property value changes, the value will trickle down to the CTA @​supports (animation-timeline: scroll()) { body { animation: show-cta both steps(1); animation-timeline: scroll(root); animation-range: 0 10vh; } @​keyframes show-cta { to { --show: 1; } } } Using @​supports you can use this as a progressive enhancement. If scroll-driven animations are supported, use them. Otherwise fallback to using position: sticky 🤙 That's it! As always, any questions or requests, hit me up! 🙏 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

133,003 просмотров • 2 лет назад