Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

Future CSS Tip! ⚡️ You can combine CSS :has() & :user-valid/:user-invalid to power micro interactions 😍 No JavaScript. Watch for the little animations ✨ label { --color: var(--default); color: var(--color); border-color: var(--color); } .group:has(:user-valid) { --color: var(--valid); } .group:not(:focus-within):has(:user-invalid) { --color: var(--invalid); } These new pseudo-elements only fire once...

283,892 görüntüleme • 2 yıl önce •via X (Twitter)

10 Yorum

jhey ▲🐻🎈 profil fotoğrafı
jhey ▲🐻🎈2 yıl önce

Here's that @CodePen link! 🚀 Wildly. This one has "varied" support atm. It works in Safari Technology Preview ✅ In Chrome 118 it works to activate but then doesn't deactivate 🤔 In Firefox, the :has() flag in Nightly doesn't work for me atm 🥲

jhey ▲🐻🎈 profil fotoğrafı
jhey ▲🐻🎈2 yıl önce

You could already do this if you have access to :has() 👀 But it requires somewhat of a transparent placeholder hack 🤓 .group:not(:focus-within):has(:invalid:not(:placeholder-shown)) { ... } Here's the @CodePen for that way 👇

Middle-belt Jay profil fotoğrafı
Middle-belt Jay2 yıl önce

Man! 😲

jhey ▲🐻🎈 profil fotoğrafı
jhey ▲🐻🎈2 yıl önce

You can do a version with :has() alone. But it isn't as clean as using :user-valid/:user-invalid IMO 🤓

Muwaffaq Elbadawi profil fotoğrafı
Muwaffaq Elbadawi2 yıl önce

Pretty hot 🔥🔥🥵

jhey ▲🐻🎈 profil fotoğrafı
jhey ▲🐻🎈2 yıl önce

We're trying! 😍

Helios Dev profil fotoğrafı
Helios Dev2 yıl önce

I wonder if you can combine this with :after { content: “invalid email”; } somewhere above the input.

jhey ▲🐻🎈 profil fotoğrafı
jhey ▲🐻🎈2 yıl önce

You could! 💯 An explicit element could be an easier solution to maintain. The idea here is also that I'm leaning into the built-in validation of the browser. So you would get the little browser built-in tooltips 🤓

fa fa-code 2x profil fotoğrafı
fa fa-code 2x2 yıl önce

@pikaso_me screenshot this

Pikaso profil fotoğrafı
Pikaso2 yıl önce

@jh3yy Here's your screenshot. ⚡ Want to automatically post your tweets on Instagram? Visit

Benzer Videolar

CSS Tip! 💪 You can create these tab controls with CSS :has() + radio buttons ✨ .tabs:has(input:nth-of-type(3)) { --count: 3; } .tabs:has(:checked:nth-of-type(3)) { --active: 2; } .tabs::after { translate: calc(var(--active, 0) * 100%) 0; width: calc(100% / var(--count)); } Two CSS :has() tricks here combined with a rendering trick 🤙 The tab control is a container using display: grid. You can use :has() to count the number of tabs in the container: .tabs:has(input:nth-of-type(3)) { --count: 3; } .tabs:has(input:nth-of-type(4)) { --count: 4; } Using the cascade, the last valid :has() gives you the number of tabs 🫶 Once you know the number of tabs, you know how to size the indicator: .tabs::after { content: ""; position: absolute; height: 100%; width: calc(100% / var(--count)); } It's a pseudoelement that uses --count to determine its size 📏 The next :has() trick is determining which tab is active or :checked as it's an input [type=radio] .tabs:has(:checked:nth-of-type(2)) { --active: 1; } .tabs:has(:checked:nth-of-type(3)) { --active: 2; } You can use a zero-indexed translation here. If the second input is :checked, set --active: 1, then translate the pseudoelement on the tabs to that position 👉 .tabs::after { translate: calc(var(--active, 0) * 100%) 0; } The last rendering trick is using mix-blend-mode 👀 The tabs have a black background-color, the pseudoelement is white, and the label text is white. When you use mix-blend-mode: difference on the pseudoelement it will give this effect that the text transitions from white to black sliding across 😎 .tabs::after { color: hsl(0 0% 100%); mix-blend-mode: difference; } You can totally mix up the colors here though and go with a different effect. The mechanics of how you can use CSS :has() is the main point here 🙏 As always, any questions, suggestions, etc. let me know CodePen.IO link below! 👇 (There's even a Tailwind CSS play for this one too 👀)

jhey ʕ•ᴥ•ʔ

437,300 görüntüleme • 2 yıl önce