How is this possible with CSS only?!

  Рет қаралды 101,424

Kevin Powell

Kevin Powell

Күн бұрын

I’ve done reaction videos in the past where I looked at crazy codepens, and today, we’re starting a new series where I find one such codepen and see if I can understand how it was created, with a dive into the :has() pseudo-class, which is now supported in Chrome and Safari.
🔗 Links
✅ Jhey's code: codepen.io/jh3y/pen/yLKMOBm
✅ My starting code: codepen.io/kevinpowell/pen/MW...
✅ :has() browser support: caniuse.com/?search=has
⌚ Timestamps
00:00 - Introduction
00:51 - what I'm trying to copy
04:20 - Setting up my custom properties
05:01 - Using :has()
06:18 - setting up the different states
10:54 - Adding the shaking animation
12:51 - removing the animation when the input is empty
16:54 - changing the style of the button when everything is valid
19:55 - should I do more videos like this one?
#css
--
Come hang out with other dev's in my Discord Community
💬 / discord
Keep up to date with everything I'm up to
✉ www.kevinpowell.co/newsletter
Come hang out with me live every Monday on Twitch!
📺 / kevinpowellcss
---
Help support my channel
👨‍🎓 Get a course: www.kevinpowell.co/courses
👕 Buy a shirt: teespring.com/stores/making-t...
💖 Support me on Patreon: / kevinpowell
---
My editor: VS Code - code.visualstudio.com/
---
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my KZbin channel, make sure to follow me on Instagram and Twitter.
Twitter: / kevinjpowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!

Пікірлер: 126
@KevinPowell
@KevinPowell Жыл бұрын
You'll still want to use some proper validation on your forms, but for these client-side hints can make for some big improvements from a UX side of things, and it's just one of the cool things we can do with :has(), it opens up a lot of other doors as well!
@KevinPowell
@KevinPowell Жыл бұрын
@Cube Memes I upload and schedule things out in advance ☺️
@gambomaster
@gambomaster Жыл бұрын
@@KevinPowell That's cool. The comment you are reading now was scheduled 2 weeks ago by me. 😆
@widadtoumi4439
@widadtoumi4439 Жыл бұрын
Hello Kevin, can you please do a video about font families in responsive design? like when we build a website with a certain font family, should we change it to roboto when the website is open on a mobile screen ? Thank you so much 😊
@djdx2
@djdx2 Жыл бұрын
I like this style Kevin, where you and the viewers are learning/experimenting at the same time. Not just you saying this that this that, you are learning as we are!
@djdx2
@djdx2 Жыл бұрын
KEVIN LOVED MY COMMENT WWWOOOOOOO
@sharkinahat
@sharkinahat Жыл бұрын
There's always something I learn from these videos. Today I learned that has() is awsome and that a placeholder pseudo-element exists.
@sergeyvolodin5798
@sergeyvolodin5798 Жыл бұрын
Hello , Kevin, you create an amazing and nessesary content ) I’m from Russia and I work as a frontend developer. My main problem was how to create really responsive websites without any difficulties and you and your content have helped me to increase the quality of my knowledge about responsive web design. Have a good day, dude 🙂🙂
@kierandansey7293
@kierandansey7293 Жыл бұрын
This is really helpful, thank you very much! I have been using js to manage form validation state primarily because of the form being invalid when the page first loads and having to juggle css selectors cross browser is a "pain in the css". But this approach is actually rather simple and logical, as soon as I saw the has(:placeholder-shown) selector it clicked what he was doing. Very clever!
@VasilyPavlik
@VasilyPavlik Жыл бұрын
Marvelous as usual! Thank you !
@eugenbleck
@eugenbleck Жыл бұрын
This was awesome Kevin!
@zaktreister1995
@zaktreister1995 Жыл бұрын
Loved this. Keep doing these!
@zachjensz
@zachjensz Жыл бұрын
Another good UX addition could be cursor: not-allowed on the button when it's greyed out.
@markboots_
@markboots_ Жыл бұрын
and maybe pointer-events to none. (although tabbing and enter will still work)
@trinkel8
@trinkel8 Жыл бұрын
And maybe disable the button?
@mityukov
@mityukov Жыл бұрын
@@trinkel8 is it possible to trigger "disabled" using css? I can only think of having two buttons and toggling each one's "display"..
@trinkel8
@trinkel8 Жыл бұрын
@@mityukov hmmmmm. Good point. JS is the only option I can think of for that. So, never mind. ☹️
@jaideepshekhar4621
@jaideepshekhar4621 Жыл бұрын
Can't we just create two buttons, one disabled, and show the proper one depending on whether the form is valid? No js required.
@theconsciousness6082
@theconsciousness6082 Жыл бұрын
Thanks for explaining everything so thoroughly.
@neoqwerty
@neoqwerty Жыл бұрын
The HAS:() pseudoclass is also supported in Firefox, but you gotta enable it as an experimental configuration! (I was looking for a good workaround to have some of my table headers change background if they used headers in their content, with a rough fallback if "has" isn't supported.)
@JansenTeam
@JansenTeam Ай бұрын
That was interesting! Yes, I would like to see the css for the spinning letters, please.
@GerritforBazeja
@GerritforBazeja Жыл бұрын
Nice to validate a form this way. Nice upgrade for the form!
@hirendarkarthikeyan6513
@hirendarkarthikeyan6513 Жыл бұрын
Hi Kevin, you are such an inspiration to me and changed my life
@mdshohidulislam5836
@mdshohidulislam5836 Жыл бұрын
Amazing to see how things start from scratch ..
@mouadhnida4639
@mouadhnida4639 Жыл бұрын
I love seeing notifications from you
@PrinceKumar-mf3tl
@PrinceKumar-mf3tl Жыл бұрын
I really appreciate it ❤️☺️. Keep continue.....
@kolbecrypto2976
@kolbecrypto2976 Жыл бұрын
Tnx kevin i learned a lot from you❤
@trinkel8
@trinkel8 Жыл бұрын
Damn. I just finished a form at work and now I want to start over. I checked out the spinning letters in CodePen and it's really quite simple.
@CirTap
@CirTap Жыл бұрын
**don't bother to regex your email fields!** whatever you enter, it's likely incomplete and breaks with intl. address formats, names, and RFC mail extensions. HTML provides the email input type for a reason, which performs a validation check against valid email address patterns. It will work better than any random regex you can find or come up.
@ACE46
@ACE46 Жыл бұрын
19:17 USE "pointer-events: none;" and "pointer-events: auto;" to disable btn in invalid state and enable in valid :)
@ap6471
@ap6471 Жыл бұрын
A true CSS Hero on KZbin 🥇
@canadianavenger
@canadianavenger Жыл бұрын
Very cool, it's amazing how far CSS has come. Might be an interesting exercise to see if you can re-create it without using the experimental `has` pseudo-class.
@KevinPowell
@KevinPowell Жыл бұрын
It's not experimental anymore, it's fully supported in Chrome and Safari :). Should be here soon-ish with FF as well (granted that doesn't mean we can use it in production yet, but it's getting there!) As for re-creating it without it, I guess we could use some sort of `label + input:valid` and other stuff like that to get us pretty close :)
@canadianavenger
@canadianavenger Жыл бұрын
@@KevinPowell Sorry, by experimental I just meant a feature that wasn't sufficiently supported out in the wild yet. But good to know it is fully adopted, and that all the other browsers should be catching up to support it "soon". Still, I think it might make for an interesting exercise. Thanks again for all the great content, I'm always learning something from your streams.
@Xamy-
@Xamy- Жыл бұрын
@@canadianavenger I’ve tried and I ran into some edge cases IIRC
@jaideepshekhar4621
@jaideepshekhar4621 Жыл бұрын
@@KevinPowell Is it supported on the Brave browser?
@CanadianPenny
@CanadianPenny Жыл бұрын
Definitely the letter flipped thing, please. That's what I clicked on the vid for. :)
@bayoutown
@bayoutown Жыл бұрын
Thanks!
@KevinPowell
@KevinPowell Жыл бұрын
Thank you so much (and sorry for missing this until now!)
@tommyandersen4004
@tommyandersen4004 Жыл бұрын
To enable in Firefox, set: `layout.css.has-selector.enabled` in about:config to True.
@Morrile1
@Morrile1 Жыл бұрын
Breaking down someone else's code can help others to understand code better, so please keep it up 👍
@bilalsalmi4136
@bilalsalmi4136 Жыл бұрын
I'm currently learning javascript , but after watching some of your CSS-only video series , I would rethink of the purpose of using js in some cases where it could be done just with CSS . JS is decreasing speed and performance of websites , js forms as calculator compared to mental-math , it's makes us more and more stupid . kevin Powell::after : { content : 'thank you so much for just amazing content' }
@claykrr
@claykrr Жыл бұрын
js helps you understand that there is absolute no limit on for example forums so you can be flexible with css and always know what’s next
@kinstar
@kinstar Жыл бұрын
you still want to keep learning though
@castlemoyle
@castlemoyle Жыл бұрын
If you HAVE to "hide" the characters in a password input, then give the user the option to SHOW the chars as you type. I hate getting locked out of a site because my fat fumble fingers have screwed up "typing" on a phone. Even if you can see the chars in a password, they are encrypted when sent. And hopefully, we know enough to beware of shoulder surfers stealing stuff. (Good comment with 2 samples of unplanned alliteration. grin). Great podcast!
@thomaskcollins
@thomaskcollins Жыл бұрын
Love this reverse-engineering breakdown approach! Thank you for this. Hope we get more videos in this format. 👍
@nathanmiddleton1478
@nathanmiddleton1478 Жыл бұрын
Take this with a grain of salt; for performance what's the overhead difference between JS and CSS for this? I know you typically don't nerd out on these things, but it'd be an interesting thing to consider. Also, nothing wrong with more videos breaking down nifty things you see IMO!
@markuserdmann1722
@markuserdmann1722 Жыл бұрын
Wonderful! We really need :has()! Maybe you can disable your submit button with pointer-events: none while the form is invalid to prevent the submit?
@KevinPowell
@KevinPowell Жыл бұрын
That could work, but it might leave people wondering what's wrong if they haven't filled out all the fields and don't see any errors, so you'd want to be a little careful :)
@markboots_
@markboots_ Жыл бұрын
probably Kevin made this tutorial earlier. But last tuesday Chrome v105 is released which includes the :has() selector. So it should work without the flag (make sure you have updated to the latest chrome version)
@stephenJpollei
@stephenJpollei Жыл бұрын
Yes and hopefully FireFox will have has very soon as well. I think it is behind flag at the moment.
@CirTap
@CirTap Жыл бұрын
@@stephenJpollei yep: go to about:config and enable `layout.css.has-selector.enabled`
@donnyestee
@donnyestee Жыл бұрын
Imagine a change request to change to label "Email" to "Email address". And then a comment of your UX designer and PO, "it's just changing a label; it shouldn't take longer than a minute".
@MrNickP
@MrNickP Жыл бұрын
When I was working through this example I implemented the animation control as .form-group:has(:invalid:not(:focus):not(:placeholder-shown)) { animation: shake 0.65s; } In this particular scenario, is there an advantage to splitting it?
@KevinPowell
@KevinPowell Жыл бұрын
oh, nice. As long as that works, it's nice having it together :)
@gobideveloper111
@gobideveloper111 Жыл бұрын
Please make a detailed video on container query because chrome supporting it.
@KevinPowell
@KevinPowell Жыл бұрын
It's on my schedule already :D
@avertry9529
@avertry9529 Жыл бұрын
I just updated Brave, which uses Chrome Engine, and :has is now supported. do you know what the popup warning is on Jhey's code? I cannot find it. and his code works without issue? The unsupported popup shows in this video too. So I just wonder what we are missing, seeing as you enabled canary experimental?
@KevinPowell
@KevinPowell Жыл бұрын
popup is a new thing that's being trialed. I've read about it, but forget the details.
@avertry9529
@avertry9529 Жыл бұрын
@@KevinPowell Thanks
@MrNickP
@MrNickP Жыл бұрын
Is there anyway to measure performance of a CSS only solution vs a CSS/JS solution?
@nomad100hd
@nomad100hd Жыл бұрын
I'm curious as well!
@KevinPowell
@KevinPowell Жыл бұрын
There are ways, but I have no idea what they are 😅. That type of testing is beyond me, but I'll try to look into it and find out how we can do proper testing for that, as it can be pretty important.
@dankierson
@dankierson Жыл бұрын
All fine but form fields must always be checked on server side even if you have them validated at client side. I like the shake and shimmer 😁
@KevinPowell
@KevinPowell Жыл бұрын
100% it needs to be checked server side too! but some UX hints for the user are always nice :)
@Xamy-
@Xamy- Жыл бұрын
I like to think of it as a multi layered approach
@arjix8738
@arjix8738 Жыл бұрын
after all, client side validation is nothing since any program can send GET and POST requests so there is no need to run the browser, aka the validation wont even run
@CJ-ff1xq
@CJ-ff1xq Жыл бұрын
Your software engineers were so preoccupied with whether or not they could, they didn't stop to think if they should.
@peteharrison3241
@peteharrison3241 3 ай бұрын
Kevin, in Jhey's code there are styles like this "--word-total:1" Can you explain this, maybe I'm just missing something
@ColossalMcBuzz
@ColossalMcBuzz Жыл бұрын
For a browser called The New IE, I can't believe Safari has had default support for *has* for about six months now.
@Metalmine
@Metalmine Жыл бұрын
A browser owned and controlled by one company vs a browser created, maintained, and updated based on an open source codebase is very different. It's like comparing the speed of change between and authoritarian government vs a democratic one. The latter might do things slower, even significantly sometimes, but It needs to as it requires multiple consensus.
@thedacian123
@thedacian123 Жыл бұрын
Form :valid sudo class is an experimental one,i mean very new?Thanks!
@KevinPowell
@KevinPowell Жыл бұрын
It's been around for a *long* time now!
@michaelschone3406
@michaelschone3406 Жыл бұрын
... and if i try to get the password i just need to interact with the css and test the animation till i get the green one? Im wrong at this pt? :peace:
@himabimdimwim
@himabimdimwim Жыл бұрын
"if your browser is Firefox you should... Switch-" 😲
@peteharrison3241
@peteharrison3241 3 ай бұрын
how could this become part of a toolset so including a stylesheet would bring this into play with any signup/sign-in form? Maybe this it too big an ask, but having hundreds of snippets it's hard to work out how to genericyfy (spelling) these to use just about anywhere.
@keylanoslokj1806
@keylanoslokj1806 Жыл бұрын
What CSS libraries and frameworks are you using?
@KevinPowell
@KevinPowell Жыл бұрын
None 😂. I have my own system using Sass, that is sort of like a framework I guess.
@CalebHesse01
@CalebHesse01 Жыл бұрын
Out of curiosity, it seems that the CSS editor allows for SCSS syntax... why not use that for variables at least? Possibly because you're showing this to people who may want to try it and don't use SCSS maybe? I would also assume the outcome would remain the same if you did use SCSS variable syntax. P.S. I have been using vanilla CSS for years. A few months ago I decided I wanted something different. I wasn't even really thinking about wanting the "new features/syntax", more like, wanted something new to try. I will probably never go back unless I need to. I have noticed that it's so much better. The only downfall for me is that it's compiled and most people probably want ctrl+s to do all the work 🤣 Though I just leave my command line open on my 3rd monitor and just click, up-arrow enter to compile. So usually it's pretty quick after you get used to it
@divinsmathew
@divinsmathew Жыл бұрын
Could've added a pointer-events: none and cursor: not-allowed to simulate the button disabled state.
@vedantkanoujia
@vedantkanoujia Жыл бұрын
But with css framework these things are easily and fastly done for production, if you are free or jobless you can done it with css or html only whole day
@mariajegan2409
@mariajegan2409 Жыл бұрын
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 40%, 60%, 80% { transform: translateX(-4%); } 10%, 30%, 50%, 70%, 90% { transform: translateX(4%); } }
@cloudsquall88
@cloudsquall88 Жыл бұрын
Does :not(:focus) mean "when losing focus" and "not having focus" at the same time?
@Metalmine
@Metalmine Жыл бұрын
losing focus is an event trigger, not having focus is an object state, since these stylings are detailed for object state, when the state changes, then it gains new properties.
@FdWebdesign
@FdWebdesign Жыл бұрын
Good Job
@Qbe_Root
@Qbe_Root Жыл бұрын
This should be doable without :has by having the form groups be fieldsets. Fieldsets, like forms, will match :valid and :invalid if their contents do, removing the need for :has(:valid) and :has(:invalid). As for :has(:focus), :focus-within should do
@jasperdiscovers
@jasperdiscovers Жыл бұрын
i wish firefox has() support for this. it's coming tho!
@bn5055
@bn5055 Жыл бұрын
I often ask myself where the Javascipt is. I always end up using Javascript instead 😉
@31redorange08
@31redorange08 Жыл бұрын
“JavaScipt” 😉
@fredbluntstoned
@fredbluntstoned Жыл бұрын
Since this is only for Chrome. It's not CSS, it's a feature of Chrome. So if you only have chrome users then you're ok. Otherwise you need to either: a. Wait until other browsers are supported. b. Make your own version for other browsers that behaves about the same. c. Not use this at all.
@QwDragon
@QwDragon Жыл бұрын
Actually :has(:focus) is :focus-within :)
@mervinmarias9283
@mervinmarias9283 Жыл бұрын
"That's the easy part"
@szaboistvan7517
@szaboistvan7517 Жыл бұрын
Should've removed pointer events for the disabled submit button
@KevinPowell
@KevinPowell Жыл бұрын
That would work, but if the user skips a field and the button is disabled, it might be a bit confusing, it'd be nice to get a tip to ask them to fill out the missing one I think, instead of having to figure out the problem :)
@koolmind
@koolmind Жыл бұрын
Why we have to write :has(:invalid:not(:focus)) instead of :has(:invalid):not(:focus) Focus should be a pseudo-class of the input itself, isn't it? :o
@Technoph1le
@Technoph1le Жыл бұрын
If we write what you have said, it would be relative to form itself not it's input
@AJman14
@AJman14 Жыл бұрын
^ Explanation: You want to make sure the :invalid input is :not(:focus) instead of the element that :has() the invalid input.
@yousseferraki723
@yousseferraki723 Жыл бұрын
, during the second wave..
@leoschuler
@leoschuler Жыл бұрын
a good artist copy a great artist steals
@davivify
@davivify Жыл бұрын
From what I can tell _:has_ has very low browser support - as of the end of June.
@Metalmine
@Metalmine Жыл бұрын
As of this week, Chrome and Safari both support it I believe, Firefox is coming soon.
@ruthlessadmin
@ruthlessadmin Жыл бұрын
I thank gods I do not believe in every day, that I got out of web development. CSS/HTML is absolute insanity. Pure high-level coding HELL.
@jaideepshekhar4621
@jaideepshekhar4621 Жыл бұрын
Because of loc?
@KennethKolano
@KennethKolano Жыл бұрын
Not really CSS only, this is CSS + HTML5.
@MrKOHKyPEHT
@MrKOHKyPEHT Жыл бұрын
Yeah, it's cool, but it's never using at commercial :D
@KevinPowell
@KevinPowell Жыл бұрын
Oh, it's not ready for production yet, but that doesn't mean it never will be! Browser support will be pretty high by the end of the year for :has(), and while you might not want to use this use case, I think it does a nice job of showing what's possible with it :)
@shiekhpalace2401
@shiekhpalace2401 Жыл бұрын
Do you know about kaboom js
@KevinPowell
@KevinPowell Жыл бұрын
I never had, but just looked now! Looks really cool, but I don't do much game stuff.
@shiekhpalace2401
@shiekhpalace2401 Жыл бұрын
@@KevinPowell i wanted a complete tutorial of kaboom js because i want to become a game developer
@siddiqahmed3274
@siddiqahmed3274 Жыл бұрын
@@shiekhpalace2401 check code with harry
@shiekhpalace2401
@shiekhpalace2401 Жыл бұрын
@@siddiqahmed3274 but he had not uploaded full tutorial i wanted full
@siddiqahmed3274
@siddiqahmed3274 Жыл бұрын
@@shiekhpalace2401 kevin is not a js guy. You have to find it somewhere else
@_lun4r_
@_lun4r_ Жыл бұрын
Your thumbnail has a typo: "JavaScipt" instead of "JavaScript"
@user-wq9mw2xz3j
@user-wq9mw2xz3j Жыл бұрын
i dont understand but then again I only have cs:go
@ShubhamSingh-sn9cy
@ShubhamSingh-sn9cy Жыл бұрын
I just installed tNice tutorials program and just looking at it makes my brain hurt lol
@IbrahimKwakuDuah
@IbrahimKwakuDuah Жыл бұрын
I always tell people: There's no shame in copy and paste
@yigit2024
@yigit2024 Жыл бұрын
respond to you all in 1 month to see how tNice tutorialngs have evolved if I rember or if soone is interested. My failure is just that - mine. But I
@thenerd3722
@thenerd3722 Жыл бұрын
honest with myself. once you find what you really want to acNice tutorialeve in life, try your best to pursue it as soon as possible. im only rn but i
@randomdude0nyoutube
@randomdude0nyoutube Жыл бұрын
Shamelessly stealing this... 🤣🤣🤣🤣 The whole lot of it
@solvedfyi
@solvedfyi Жыл бұрын
I don't understand why your "look at some codepens" videos are so SO much more popular than your other videos. Makes me wonder what that incentivizes you to make. Not only do the views come but they should be easier to record, just scrolling through pens. But we get far less education from it.
@ItsMeooooooo
@ItsMeooooooo Жыл бұрын
I stopped watching as he said: "When you use Firefox, you have to switch Browsers". The main Purpose of a webpage is to deliver Information. All of your fancy shmancy CSS stuff isn't worth to take a look at when its not compatible with all of the browsers. The route your are taking here is bring back the old times of "Optimised for Internet Explorer". Are you sure you want them back?
The new CSS pseudo-classes explained - :is() :where() :has()
13:50
Kevin Powell
Рет қаралды 131 М.
New CSS Units! Container Query Units explained
13:42
Kevin Powell
Рет қаралды 62 М.
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 26 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 10 МЛН
7 ways to deal with CSS
6:23
Fireship
Рет қаралды 1,1 МЛН
Create direction-aware effects using modern CSS
18:30
Kevin Powell
Рет қаралды 64 М.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Рет қаралды 915 М.
How to create a theme switcher with HTML & CSS
28:21
Kevin Powell
Рет қаралды 109 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 359 М.
A look at the CUBE CSS methodology in action
47:09
Kevin Powell
Рет қаралды 102 М.
Container Queries are going to change how we make layouts
24:24
Kevin Powell
Рет қаралды 170 М.
Animated Responsive Navbar with CSS - Plus Other Useful Tricks
11:40
Stop using JS for things that CSS can solve
9:13
Kevin Powell
Рет қаралды 75 М.
The secret to mastering CSS layouts
17:11
Kevin Powell
Рет қаралды 268 М.