Пропустить навигацию
CSS Tip! ✨ You can lean into form control state and layered backgrounds to create input status…
0:00 / 0:27

CSS Tip! ✨ You can lean into form control state and layered backgrounds to create input status…

jhey ʕ•ᴥ•ʔ

@jh3yy147 тыс. подписчиков

Открыть в X
1 826 отметок «Нравится»СкачатьОригинальный пост

239 700 просмотров

CSS Tip! ✨ You can lean into form control state and layered backgrounds to create input status strokes 😎 input:valid { --valid: 1; } input { background: var(--bg) padding-box, ..., var(--valid-bg) calc((1 - var(--valid)) * 100cqi) 0 / 100% 100% border-box; } The trick is to layer up backgrounds using background-clip to leave a border space 🤏 Applying a transparent border gives you the space for the layered background to transition in 🎞️ Then you can use custom properties to dictate the background-position of each layer. By default, the valid and invalid layers are positioned outside the bounding box. But when one of those states is active, the background layer transitions in to 0 0. To respect people's animations preferences, we can wrap that transition in a media query 🤙 @​media (prefers-reduced-motion: no-preference) { input { transition: background-position: 0.5s; } } Was revisiting techniques around :has and :user-valid and it dawned that you could do it like this too! Hope you find it useful! p.s Don't rely on color to communicate form status. It's a cool trick though for an added touch ✨ CodePen.IO link below! 👇

9 комментариев

Комментарии из оригинального поста в X (Twitter)

  • Фото профиля jhey ▲🐻🎈

    @jh3yy

    Here's that @CodePen link! 🚀 Should rock in all browsers 🤙

    55 отметок «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @jh3yy

    Haha - Thanks Masda 🤙

    1 отметка «Нравится»

  • Фото профиля Pratyay Banerjee (নীল) 

    @Neilzblaze007

    Ummmm

    2 отметки «Нравится»

  • Фото профиля jhey ▲🐻🎈

    @jh3yy

    Interestingly, that's valid. There are some funky email patterns that are valid for email. You can take it further with the "pattern" attribute if needed. Quite cool if you wanted to only accept email from certain domains, etc.

    7 отметок «Нравится»

  • Фото профиля Marcel

    @MarcelFromMimic

    How can you make tweets so long, for me if its too long it just doesnt work.

    2 отметки «Нравится»

  • Фото профиля TypeScriptGuru

    @TypeScriptGuru

    🔥🔥

    1 отметка «Нравится»

  • Фото профиля Sebastian

    @hiiinternet

    @artur_bien

    1 отметка «Нравится»

  • Фото профиля Armin~the Vlone{tech} thug

    @minraxoxo

    Wow

    1 отметка «Нравится»

  • Фото профиля Alex Leybourne

    @AlexLeybourne

    Just when I think i’m pretty good and knowledgeable at css You somehow tech me something new almost every day 🤩

    1 отметка «Нравится»