跳过导航
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 ʕ•ᴥ•ʔ

@jh3yy15万 位关注者

在 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 个赞