Stop using JS for things that CSS can solve

  Рет қаралды 75,279

Kevin Powell

Kevin Powell

Күн бұрын

Sometimes we need to do something, and when there is no obvious answer, we come up with really complex solutions. There are some useful pseudo-classes that give us really simple solutions thought!
🔗 Links
✅ Amit's JavaScript Problems, CSS Solutions video: • JavaScript Problems, C...
✅ Amit's Twitter: / amit_sheen
✅ Code from this video: codepen.io/kevinpowell/pen/MW...
⌚ Timestamps
00:00 - Introduction
00:39 - :empty
04:04 - :target
06:20 - :only-child and :only-of-type
#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!

Пікірлер: 161
@ZaidMarrie
@ZaidMarrie 2 жыл бұрын
I never knew about the :empty psuedo class. I feel like Kevin reveals all the secrets of HTML & CSS. Thanks Kevin!
@AbdicateDotNet
@AbdicateDotNet 2 жыл бұрын
"Front-end fiends!" It's getting better. Great job! I love your videos.
@novanoskillz4151
@novanoskillz4151 2 жыл бұрын
😂😂😂
@darshanrajpattanaik2154
@darshanrajpattanaik2154 2 жыл бұрын
How you commented 1 days ago, video released 2 hours ago?
@julianflorez9972
@julianflorez9972 2 жыл бұрын
'Friend and friends' lol
@j-janz
@j-janz 2 жыл бұрын
Automatic captions still think it's friend and friends, though. 😅
@solvedfyi
@solvedfyi 2 жыл бұрын
fiends be feenin'
@hikari1690
@hikari1690 2 жыл бұрын
More please! I feel stupid everytime I think of the time I've wasted solving with js but I look forward to the years I'll save with these
@kristianvassilev360
@kristianvassilev360 2 жыл бұрын
Selecting a parent? I've been waiting for that for years! Please show us 👍
@KevinPowell
@KevinPowell 2 жыл бұрын
I'll do a video on it soon-ish... for now, you can look up the :has() selector, but support for it is a ways off still
@efdrgn
@efdrgn 2 жыл бұрын
@@KevinPowell this should've been implemented a lot sooner! Need this ASAP Kevin speak to the web masters please!
@threeone6012
@threeone6012 2 жыл бұрын
I've programmed for years but I've never used :empty or :target. So awesome, thanks Kev!
@MrJettann
@MrJettann 2 жыл бұрын
Awesome content, Kevin!! I definitely want to see more such videos!
@kevinfisher7032
@kevinfisher7032 2 жыл бұрын
Kevin, kudos…another super useful video. I always look to CSS as the easiest, most bulletproof way to just get things done. For anyone who has been doing this longer than 5 years it’s great to see CSS easily solve problems that used to take hours of javascript faffing to do.
@JDalmasca
@JDalmasca 2 жыл бұрын
Great tips! Definitely the right level of not-that-well-known, but also useful! Keep up the great work, Kevin! We appreciate it!
@khalidsaifullahfuad
@khalidsaifullahfuad Жыл бұрын
Wow, that's really helpful. I recently faced the empty error message problem and fixed it with JS. Please make more videos like this.
@pupinarvaja
@pupinarvaja 2 жыл бұрын
Loved the "scroll behaviour smoOoth" 4:25
@arthurcouto5163
@arthurcouto5163 2 жыл бұрын
kevin pls keep making videos, you really help me and many people to continue on this way of front-end development
@mj2758
@mj2758 2 жыл бұрын
Thank u so much Kevin and great content. we're really in need of these kind of videos
@anushikabhardwaj7201
@anushikabhardwaj7201 2 жыл бұрын
Wow, thank you so much. I needed this. Especially, this :empty is going to solve my problem 😇
@Yukitocyborg
@Yukitocyborg 2 жыл бұрын
Awesome content! Only-child is really good, it would have solved a problem I had before.
@evandromottaz
@evandromottaz 2 жыл бұрын
Very nice Kevin, thanks for the useful tricks. Specially the :target...
@vasyaqwe2087
@vasyaqwe2087 2 жыл бұрын
Great tips as always, Kevin! Waiting for :has video
@WellSaint001
@WellSaint001 2 жыл бұрын
Thanks Kevin! This is really useful
@alejandroingercher3020
@alejandroingercher3020 2 жыл бұрын
I really enjoy your content. You are like a box full of surprising css tools
@willsoe
@willsoe 2 жыл бұрын
Here's a contribution to this idea from a newbie. I once wrote a load of js to manage clicks on an animation of a timer wheel which would trigger a new image from the server. I got rid of it all and instead made the click end the animation and then attach a listener to an animationiteration to trigger the new image download. No js timing needed!
@yt_brij
@yt_brij 2 жыл бұрын
Target and Empty is new for me Thanks for the informative Video 😉
@yaycupcake
@yaycupcake 2 жыл бұрын
would love to see content on the has selector but also an update video on when it's usable too
@AndreaASalvatierra
@AndreaASalvatierra 2 жыл бұрын
thank you! would love to know more about the has selector :D
@Karthik-ug8ll
@Karthik-ug8ll 2 жыл бұрын
Hey kevin, Thanks for awesome contents,looking forward video on how "has" function works in css,thanks in advance😊
@demicoderr
@demicoderr 2 жыл бұрын
Thank you so much Kevin! Love your videos
@qwertgfhxc
@qwertgfhxc 2 жыл бұрын
You're the best Kevin, keep going! :)
@codernerd7076
@codernerd7076 2 жыл бұрын
Thanks I learned some new things! I'm a big fan of keeping things simple and get some work done 😁👍
@NottsKnots
@NottsKnots 2 жыл бұрын
Hi Kevin, started watching your videos recently and there is lots of intresting stuff here. One request, could you cover some 'practical' topics in depth at some point? Perhaps your best practices for starting a new Bootstrap site with the current version? (seen the old series you did.) Or talk about an overview of how your organise your CSS and why? What is the best way to arrange CSS to make best use of cascading? In other words, taking the things you have shown from your more ' flashy' videos and showing how to apply the knowledge to a typical real world project. Thanks.
@dillanclark864
@dillanclark864 2 жыл бұрын
I've watched a few of your videos before and I was like, yeah okay you have some good tips. But you sir, have earned yourself a sub and a like after these nifty little tricks. Very well done!
@Brandon-bg2de
@Brandon-bg2de 2 жыл бұрын
Nice video Kevin! I am wondering is it possible for built in css to handle click outside alerter for multiple mapped elements? Let’s say when we clicked outside of each element, the corresponding clicked element dissapear. I currently implement it with Javascript but it would be interesting if css can handle this too :)
@TechBuddy_
@TechBuddy_ 2 жыл бұрын
In the target selector add an animation that just changes the brightness filter for a bit to highlight the target element instead of a red outline which I use all the time,it's easy to write, easy to use and very effective.
@CirTap
@CirTap Ай бұрын
Pseudo selectors can also be combined: p:only-of-type:not(:only-child) for the single paragraph with the image, or the other way around: img:first-child + p:only-of-type to ignore the one with multiple paragraphs, again use :not() to reverse the logic.
@arafat64
@arafat64 2 жыл бұрын
we are appreciate your effort Kevin thanks, I love the dynamic development logic it's very useful and helpful to save our time.
@techforsolution2505
@techforsolution2505 2 жыл бұрын
Cool! I like the :target one.
@bo4695
@bo4695 2 жыл бұрын
Hi mate, thanks for the tutorial! I was wondering if it is possible to remove the styles for the " :target " element for like after a few seconds or even based on an event. Thanks!
@sahilmehraa
@sahilmehraa 2 жыл бұрын
Your videos has saved my time and efforts almost everyday. 😁
@cseymour97
@cseymour97 2 жыл бұрын
Target is one of my favorites. I love using it for dynamic tabs.
@ArifMatubber-km4nv
@ArifMatubber-km4nv 2 жыл бұрын
that was awesome thing. wow Thank you so much Kevin
@e11world
@e11world 2 жыл бұрын
I like the :target selector and I think a nice way to implement it would be to have an animation tied to it. Example would be to highlight in a way but fade it out after 1s.
@AverageCho
@AverageCho 2 жыл бұрын
Thats an awesome idea. Nice one two combo
@e11world
@e11world 2 жыл бұрын
@@AverageCho Thanks yea this target selector is amazing for this and if you already have smooth scroll in CSS, it's that much nicer.
@MMH94MMH
@MMH94MMH 2 жыл бұрын
You are amazing Kevin, this video is a life changer for me.
@toguppy1985
@toguppy1985 2 жыл бұрын
Love :target pseudo selector. have played with this and an animation so that it runs, identifies the area, and then removes the identifier
@xingfucoder2627
@xingfucoder2627 2 жыл бұрын
Hi Kevin, great video. When will be available your SASS course?
@crim-son
@crim-son 2 жыл бұрын
You're making JavaScript Redundant with your videos 🥺🥺😍😍, Good work Mister Kevin
@soul.rebel1986
@soul.rebel1986 2 жыл бұрын
Awesome as always 🎉
@fazlerabbi9200
@fazlerabbi9200 2 жыл бұрын
These are really awesome!
@FunBSDpami
@FunBSDpami 4 ай бұрын
Great tips. Thx!
@darkpain4208
@darkpain4208 2 жыл бұрын
Thanks, Kevin. You changed my life.
@RaviRambaran
@RaviRambaran 2 жыл бұрын
Yes! Thank you Kevin!
@kamilcopur6513
@kamilcopur6513 2 жыл бұрын
Perfect... Thank your for sharing..
@djvesko
@djvesko 2 жыл бұрын
Thanks for these!
@rickardelimaa
@rickardelimaa 2 жыл бұрын
Just learned about _:empty_ a month ago when a markup script generated empty (p)aragraphs for row-breaks. Just thought "wonder if CSS has a solution for this". Will use _:target_ in the future. Learned something new there.
@AndreSpecht
@AndreSpecht 2 жыл бұрын
Hi Kevin. Do you have a video that explains the differences between styles in html and * selectors? Thanks
@aram5642
@aram5642 2 жыл бұрын
I would be curious to see you refactor css of a site, getting rid of complex selectors in favor of where and is.
@kiravolvo
@kiravolvo 2 жыл бұрын
thank you kevin. you rock!
@MarekFodor
@MarekFodor Жыл бұрын
Damn, this is really helpful and saves lot of time.
@MikeyMoNL
@MikeyMoNL 2 жыл бұрын
Before I found out about only-child I just used :first-child:last-child. That does the same trick.
@misticx
@misticx 2 жыл бұрын
Very useful tips, gj.
@alanlewis1625
@alanlewis1625 2 жыл бұрын
Hi Kevin, nice video. The features you mention are useful. I do have a question, -not directly related to this content- I hope you can either suggest a solution, or point to a video you have previously made. That is, if I want to 'highlight' a navigation item / tab, that is currently being displayed e.g. this page, how can I do this using only CSS? Thanks
@KevinPowell
@KevinPowell 2 жыл бұрын
You need a class that changes the styling, and apply to to the link for that page. There is nothing in CSS that can know what page is actually the active one
@NiborGnittekeduog
@NiborGnittekeduog 2 жыл бұрын
My gosh! How often I have looked for :has to check the state of the implementation. It's getting closer!!
@andertker4460
@andertker4460 2 жыл бұрын
Good content! Greetings from Bilbao!!
@jma6893
@jma6893 Жыл бұрын
oh wow, i didn't know about the :target one... that has so much potential... less .js to write haha... Thanks Kevin!
@fylip22b
@fylip22b Жыл бұрын
Thanks for these tips! I improve my CSS knowledge. Philippe P
@oohsorry4506
@oohsorry4506 Жыл бұрын
Question: if u use the empty pseudo reset thingy on everything but Img svgs does it mean u cant make boxes from divs now, cuz its empty
@CirTap
@CirTap Ай бұрын
Just noticed I could've used :target for something I did lately with JS... if I slap an id on the element this should work. 🙂
@moritzgeorgy5440
@moritzgeorgy5440 Жыл бұрын
Awesome!
@pixiedev
@pixiedev 2 жыл бұрын
Very helpful I'll use. but Is there any way to set different margin or other attributes for p tag (paragraph) if 2 p is continuous like demo para 1 demo para 2
@KevinPowell
@KevinPowell 2 жыл бұрын
You can select the second one with p + p...
@RussellDove
@RussellDove 2 жыл бұрын
Greetings, awesome content. Would you happen to know of a good web form validation script that increases accessibility by enabling screen readers to announce error messages?
@KevinPowell
@KevinPowell 2 жыл бұрын
Oh, that would be great. I don't know of one... there must be something out there though. Time to start digging
@uc9773
@uc9773 2 жыл бұрын
nice tip thanks!
@vickmackey24
@vickmackey24 2 жыл бұрын
6:44 Unrelated to your lesson, but does the pipe between "testimonials" and "flow" in the class attribute do something special here?
@404-UsernameNotFound
@404-UsernameNotFound 2 жыл бұрын
When looking at the .classList of the element using JS, it shows `DOMTokenList(3) ['testimonials', '|', 'flow']`. So the pipe is it's own class?
@KevinPowell
@KevinPowell 2 жыл бұрын
No, it's just a visual separator, picked it up from using CUBE CSS. It's technically a class that's just not doing anything at all. Might even be an invalid one, but it doesn't cause any problems.
@michaelm8044
@michaelm8044 2 жыл бұрын
You're the man, man.
@ErikBlomqvistSwe
@ErikBlomqvistSwe 2 жыл бұрын
Nice to see the usage of thisisnotarealperson to display images of people, rather than a common avatar service, Kevin!
@Technoph1le
@Technoph1le 2 жыл бұрын
Hi, Kevin! I have a question regarding custom properties. Consider you have design that has more than 10 neutral colors. And, you are assigning them in custom properties in such: :root { --clr-neutral-100: #FFF; --clr-neutral-400: #444; ..... --clr-neutral-900: #222; } In custom properties, you did assign from 100 to 900, which can hold only 9 values. What and how do you deal with the rest of the neutral colors? Would you assign them, like ---clr-neutral-100_1 or any other method? Thanks in advance.
@fredhair
@fredhair 2 жыл бұрын
From a design perspective if you've got more than 9 neutral colors, I think you're using too many colors for sure. Most color schemes only have a handful of neutral colors. You really don't need a different shade for every single component in your page. I tend to use a primary & secondary color with maybe 3 or 4 shades each and a light & dark neutral color with 4 or 5 shades. If you want to build a brand, you will likely have 2 or 3 colors that you actually use with a handful of neutral tones to complement / contrast your main colors. For most people a scale of 9 shades is more than enough for a single 'color'. You might have a light neutral and dark neutral which also have a 9 shade range but rarely will you need such fine distinctions between shades unless you're creating a gradient which you'd interpolate anyway.
@KevinPowell
@KevinPowell 2 жыл бұрын
Yeah, more than 9 shades of a color is a lot... BUT if you need to, I just keep going, lol. 900, 1000, 1100, etc. Though normally what happens is a new color gets added that's between two existing colors, which is why I like numbering in the 100s. If you have clr-neutral-1 and clr-neutral-2, it's annoying to get something in the middle... with 100s, you can have clr-100, clr-150, clr-200 etc.
@alwaysgratefulmixail7569
@alwaysgratefulmixail7569 Жыл бұрын
I've been in need of the :target pseudo class for a frontend mentor project for a whole month and something 😂 I thought I only have to use JavaScript 🤣
@andystevenson6336
@andystevenson6336 2 жыл бұрын
This is excellent Kevin. Would like to see something on :has
@Brunoenribeiro
@Brunoenribeiro 2 жыл бұрын
:target blew my mind!
@ManuelSanchez-hy8yi
@ManuelSanchez-hy8yi 2 жыл бұрын
Look forward to having your has() video!
@s7s_space
@s7s_space 2 жыл бұрын
How to make active class on links for nav in target?
@dave6012
@dave6012 2 жыл бұрын
Love this approach. CSS is powerful 💪
@dave6012
@dave6012 2 жыл бұрын
PS- waiting fervently for :has() !!
@xingfucoder2627
@xingfucoder2627 2 жыл бұрын
great video! when will be available the SASS course? 🙂
@KevinPowell
@KevinPowell 2 жыл бұрын
don't ask 🤣🤣 - taking a break from working on it to read some comments... it's getting there... slowly, lol.
@xingfucoder2627
@xingfucoder2627 2 жыл бұрын
@@KevinPowell don't worry Kevin ☺️ take rest. Thanks for quick answer
@yusi9437
@yusi9437 2 жыл бұрын
Suddenly comments have popped up about your welcoming introduction "front end friends". Up until your previous upload I always thought you were saying "friend and friends" as in to welcome the viewer personally and then everybody else 😂
@stephenJpollei
@stephenJpollei 2 жыл бұрын
Yes I thought he was saying "friend and friends" when I first started watching his videos; just thought it was part of him being super nice. I hear "front-end friends" clearly now though.
@tigrafale4610
@tigrafale4610 2 жыл бұрын
What? I was sure it was friend and friends! It's just like with TheWarOwl, "I still have no clothes on".
@abdulkadirguven1173
@abdulkadirguven1173 Жыл бұрын
Thanks Kevin
@MuhammadAhmedAshraf
@MuhammadAhmedAshraf 2 жыл бұрын
How the youtube and wikipedia has elements when they can't fit in to screen the position themselves top -215px and when there's enough space at the bottom the have top 200px like youtube has on the edit comment is through the use of intersection observer api and am i right api means functions, objects of a library and urls on web
@KevinPowell
@KevinPowell 2 жыл бұрын
My guess would be intersection observers, yes. In this case, the API is a bit different because it's one the browser uses, not an API you'd use to pull stuff from a server or whatever.
@fakefury1198
@fakefury1198 2 жыл бұрын
So at like 8:18 when you're explaining the :not(:only-of-type), I see why this is really useful, but wouldn't just giving the element a specific class be better? I know that it is generally best to stay away from complex selectors, so I was just wondering if you would normally prefer a class over doing this.
@JoeBonez
@JoeBonez 2 жыл бұрын
What is the deal with the vertical bar in the class name (“testimonials | flow”)? I’ve never seen that before, and the google is failing me.
@KevinPowell
@KevinPowell 2 жыл бұрын
Comes from CUBE CSS, it's just a visual separator between "blocks" and "utililities"
@eren1514
@eren1514 2 жыл бұрын
Hey Kevin! Love your content! but I'm really a dumb on responsive side :D May you make a clone project that focus on responsive side, such as cards, nav... thank you!
@robertcarsten4050
@robertcarsten4050 2 жыл бұрын
Have you checked out Kevin's Responsive design course? Can't post links but if you search Kevin powell responsive design it should be the first link
@ScottLee64
@ScottLee64 2 жыл бұрын
Your videos make me less unenthusiastic about CSS. Thanks!
@sssamalander
@sssamalander Жыл бұрын
Could you use this to make a carousel?
@blasfah1909
@blasfah1909 2 жыл бұрын
Cool!
@j-janz
@j-janz 2 жыл бұрын
Yes, bring :has() content on! 😊
@404-UsernameNotFound
@404-UsernameNotFound 2 жыл бұрын
:has() can be enabled in Chrome and Edge beginning in v101 with the enable-experimental-web-platform-features flag and is slated to be GA in v105.
@AbhinavKulshreshtha
@AbhinavKulshreshtha 2 жыл бұрын
About :target, wouldn't it mess with keyboard navigation? I used that property in the past for visually show the keyboard navigation. But other than that, I don't know much about it. I wish I knew about :empty in the past, I have spent so many hours hiding error messages and flash messages.
@KevinPowell
@KevinPowell 2 жыл бұрын
It shouldn't have any impact on keyboard navigation? It's just a visual clue for what's been targetted... you just wouldn't want to use the same style for :outline as you would for :target because then that would get annoying
@GmodArgentina
@GmodArgentina 2 жыл бұрын
Kevin I'm currently learning Web design but after learning css I've become obssesed with it. You think it's better to become very good at css before jumping to Javascript or i should start now ?
@KevinPowell
@KevinPowell 2 жыл бұрын
I guess it depends on how far along you are, but once you feel like you're getting comfortable with CSS, even if you're not "very good" yet, I'd probably start sprinkling in some JS
@GmodArgentina
@GmodArgentina 2 жыл бұрын
@@KevinPowell Thanks that I'll do ! Should i start from scratch or straight to react ?
@clevermissfox
@clevermissfox 4 ай бұрын
5:30 hmm “tricks” with target?? What could that be?!
@TillmanTech
@TillmanTech 2 жыл бұрын
I like those profile pictures of Jane and John in the first segment on :empty. How many times did you have to refresh the page to get such good results? 😉
@KevinPowell
@KevinPowell 2 жыл бұрын
Showed up in my first load of loremfaces.com/ :)
@emreaydogdu5413
@emreaydogdu5413 2 жыл бұрын
Keep generating videos with your style! BTW, do not you speak a lot during video :) ? This is spiritual energy!
@anushervonTabarov
@anushervonTabarov Жыл бұрын
THANK YOU FROM TAJIKISTAN !
@qm3ster
@qm3ster Жыл бұрын
I wonder if I should actually use :empty... Sounds like it would leave a bunch of hidden HTML in the DOM. I should probably just continue not including it, whether on the server or on the client.
@lukaszpiotrluczak
@lukaszpiotrluczak 2 жыл бұрын
Letting you know :)
@GR_BackingTracks
@GR_BackingTracks 8 ай бұрын
I am madly, deeply in love with CSS...
@YurijVolkov
@YurijVolkov 2 жыл бұрын
I'm working with CSS since early 2000 and I noticed that I tend not to know about new features of it. I'm just using the same thing as part of a habit, knowing that it works... You should always learn continuously! Don't make oldfags mistakes! :D
@fissure9999
@fissure9999 2 жыл бұрын
👍👍👍
@bazz6932
@bazz6932 2 жыл бұрын
Powerful
3 useful CSS hacks
8:50
Kevin Powell
Рет қаралды 69 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 10 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 12 МЛН
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
LOVE LETTER - POPPY PLAYTIME CHAPTER 3 | GH'S ANIMATION
00:15
Add and Remove Active Class on Click
5:20
ByteGrad
Рет қаралды 35 М.
Avoid These 5 Awful CSS Mistakes
20:42
Kevin Powell
Рет қаралды 190 М.
:has() opens up new possibilities with CSS
14:30
Kevin Powell
Рет қаралды 283 М.
5 Useful CSS Properties You Didn't Know
18:17
Kevin Powell
Рет қаралды 57 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 359 М.
Learn flexbox the easy way
34:04
Kevin Powell
Рет қаралды 685 М.
5 super useful CSS properties that don't get enough attention
16:23
Kevin Powell
Рет қаралды 141 М.
23 CSS features you should know (and be using) by now
31:31
Kevin Powell
Рет қаралды 65 М.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Рет қаралды 916 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 10 МЛН