How did I not know about this CSS Grid + Flexbox helper sooner?!

  Рет қаралды 39,446

Wes Bos

Wes Bos

Күн бұрын

Пікірлер: 126
@Goshified
@Goshified 3 ай бұрын
Can't believe you got me excited to go refactor some code at work Monday, at 7PM on a Friday night.
@MerthanMerter
@MerthanMerter 3 ай бұрын
for real 😀
@Clem.E
@Clem.E 3 ай бұрын
If it aint broke dont fix it.
@quinten01
@quinten01 3 ай бұрын
Real devs don't stop working on Friday. Go fix it now
@liamwinterton7370
@liamwinterton7370 3 ай бұрын
Stuff like this makes you wonder what other hidden gems / combinations are available that most developers just don't know about. I'd be utilizing this flow in all of my builds if I knew about it before just now. I need a big, 30-60 minute compilation of all these golden nuggets and I need it now!
@JohnFarrellDev
@JohnFarrellDev 3 ай бұрын
Nice, I had been duplicating the flex and gap
@AlexJewellAlex
@AlexJewellAlex 3 ай бұрын
"Put a flex grow on that thang." - Wes on the Talk Tuah podcast
@ArnoldsKtm
@ArnoldsKtm 3 ай бұрын
yikes
@sakkii
@sakkii 2 ай бұрын
bro
@jamessudimak1696
@jamessudimak1696 3 ай бұрын
I've found display: contents to be especially helpful when I have to wrap an element in an anchor tag. It's a life-saver haha
@jmg9509
@jmg9509 3 ай бұрын
Yup I do that quite often now since learning about it
@xXbxXz3ch3chvXx
@xXbxXz3ch3chvXx 3 ай бұрын
1:06 display: contents; Will tell CSS, please don't treat us like a stepchild! 😅 Thanks for sharing, Wes! 🔥
@mmahgoub
@mmahgoub 3 ай бұрын
WTF how long this been around?
@WesBos
@WesBos 3 ай бұрын
7 years :|
@backup_hdd
@backup_hdd 3 ай бұрын
​@@WesBosHUH
@edwardkenemorales
@edwardkenemorales 3 ай бұрын
@@WesBos Wow 7 years but still partially supported by major browsers :(
@JasonKaler
@JasonKaler 3 ай бұрын
Chrome android: Three weeks now
@mnpenner
@mnpenner 3 ай бұрын
@@edwardkenemorales "elements with CSS display:contents are not focusable" Yeah...maybe you shouldn't use display:contents on elements that you actually want to be interactable? Sounds like a pretty minor issue.
@CyberTechBits
@CyberTechBits 3 ай бұрын
Brother! I've been coding for years and wish I knew this sooner! I know exactly the project I can use this on! Thank you my friend!
@iamdipankarj
@iamdipankarj 2 ай бұрын
Imagine a non-tech peerson overheard this without any context. "Do not treat me as an element and treat my children as direct children of the actual parent".
@RideTheTeacups
@RideTheTeacups 3 ай бұрын
I feel like I’ve been playing on hard mode. This is fantastic! Thanks so much for sharing. 🎉🎉🎉
@lemontec
@lemontec 3 ай бұрын
Wow knowing this earlier would have saved me some headaches!
@r34ct4
@r34ct4 3 ай бұрын
Crazy that this kind of specific code will be a fringe hobbyist thing in about a year - when we're prompting full features.
@sid06
@sid06 3 ай бұрын
This just saved me when loading an SVG string via the dangerouslySetInnerHTML attribute of a proxy div because the parent grid wouldn’t otherwise center the image inside the row!
@frstylol
@frstylol 3 ай бұрын
Recently found out about this, and it makes your code so much nicer
@The14Some1
@The14Some1 3 ай бұрын
display:contents elements still handle --variables, that are defined inside them like all other normal elements do.
@errorerror1337
@errorerror1337 2 ай бұрын
Can't believe I knew something before Wes Bos, this is like discovering Plutonium by accident
@KennedyOtisNyaga
@KennedyOtisNyaga 3 ай бұрын
❤. May be it’s time for a course in all these new css feature :)
@BrianGentles
@BrianGentles 3 ай бұрын
The kicker is, it isn't new. Been around for ages.
@tomitomion1179
@tomitomion1179 3 ай бұрын
Learnt it from Tailwind, at first I thought it was their smart magic utility class but then found out it was pure CSS
@haroldpepete
@haroldpepete 3 ай бұрын
super handy, i didn't know it, thanks, you have a new subscriber for such a amazing tip
@blancfilms
@blancfilms 3 ай бұрын
This was super helpful and quick. Thank you!
@matthewallenblack
@matthewallenblack 3 ай бұрын
The CSS-TRICKS guide needs a PR! This is so rad. How'd you discover it!?
@re.liable
@re.liable 3 ай бұрын
Nice. I also just discovered `display: contents;` recently, when I needed to render a button inside a long paragraph, but have its text wrap with the paragraph. Apparently there was some accessibility issues with this rule but it seems to be okay now. Hopefully I'll remember this before I duplicate my rules for nested elements lol
@AntonEmery
@AntonEmery 3 ай бұрын
Wow. How did I never know about this? Game changer
@KoenVerheyen
@KoenVerheyen 3 ай бұрын
MIND = BLOWN!
@MightyIndians
@MightyIndians 3 ай бұрын
Just one word! *UCK with an F not Y. How i missed it in all my 8 years of development. Feeling shame. Thanks for sharing about this amazing property
@kobibr9362
@kobibr9362 3 ай бұрын
Thx the universe I found you today.
@thydevdom
@thydevdom 3 ай бұрын
Already looking forward to work on Monday to fix a 'div' from last week. 😂
@tanaybhomia2784
@tanaybhomia2784 3 ай бұрын
Which font is that , I love those curly braces.
@SametSMC
@SametSMC 3 ай бұрын
Please let me know if you found out mate
@SametSMC
@SametSMC 3 ай бұрын
Seems to be “Operator Mono”
@CodeNascher_
@CodeNascher_ 3 ай бұрын
yepp, it's operator mono
@Mika43344
@Mika43344 3 ай бұрын
Will !important work on changing colour?
@GnomePuntTrainerYT
@GnomePuntTrainerYT 3 ай бұрын
Like others and Wes have pointed out below, if you just make sure you don't use it on semantic elements and you are good. --------- Unfortunately this is not really reliable. It only has 11% support, and the remaining 85% of partial support leave buttons inaccessible if affected by "display: contents;". After 7 years of partial support, this is likely never going to make it into any stable version.
@nilaallj
@nilaallj 3 ай бұрын
May I ask, why use `display: contents` on buttons in the first place? What would the expected behavior be? How do people expect to get focusable buttons using a feature that literally skips to their descendants in the DOM? While `display: contents` can be used to skip an element while retaining its semantics, I think that's more for sectioning elements such as `` or ``, not for interactive stuff. :)
@WesBos
@WesBos 3 ай бұрын
Not the case - read the description, you just don’t use it on semantic elements like headings, buttons and tables. Use it on wrapper elements. It has full support
@jp0678
@jp0678 3 ай бұрын
Found out about this also some years ago. Very useful for solving some styling problems where you can't easily (or unable to) change the HTML.
@RocketLR
@RocketLR 3 ай бұрын
Great.. Now i just need to remember this for when i need it in like ... 4 months :(
@kengreeff
@kengreeff 3 ай бұрын
Super handy!
@untowardMedia
@untowardMedia 3 ай бұрын
I think it may be considered harmful for a11y potentially. Shame if so, because it is super useful.
@callumscott5107
@callumscott5107 3 ай бұрын
I’m just getting into web dev and this is literally a big problem I’ve just been struggling with haha.
@TejShah30
@TejShah30 3 ай бұрын
Great. You found it 😊
@cedwards1080
@cedwards1080 3 ай бұрын
I needed to see this video last week :(
@jamesxxxxxx
@jamesxxxxxx 3 ай бұрын
Bro this is insane! My life just extended several years because of this!
@moonbe77
@moonbe77 3 ай бұрын
This is fire🎉. Is this a new feature?
@hclyrics
@hclyrics 3 ай бұрын
7 years old now.
@JudeHansen
@JudeHansen 3 ай бұрын
dang, I could have used this a couple months ago. thanks.
@pyroghost11
@pyroghost11 3 ай бұрын
awesome! thank you
@mryechkin
@mryechkin 3 ай бұрын
Woah.. This is a game-changer!
@AnshumanBhardwaj
@AnshumanBhardwaj 3 ай бұрын
Damn it! That’s amazing 😮
@geelemo
@geelemo 3 ай бұрын
Display: contents. Caniuse?
@davidwebca
@davidwebca 3 ай бұрын
WHY THE HELL AM I JUST SEEING THIS. Signed by me, fighting off flex order inside wrappers for logos in footers since the dawn of time. 😂
@DrJayTap
@DrJayTap 3 ай бұрын
Ahhh I remember seeing this being used by s and was like wtf is that?? 😂 makes sense that they would want to be basically ignored in the DOM tree and non-interactive. Neat! Thanks for this cool lesson.
@johnguillen68
@johnguillen68 3 ай бұрын
I wanted to learn coding so I started to learn HTML and CSS. I want to leave my current medical job and get into coding but I'm afraid that I may not be smart enough to learn everything. I see so many videos of coders doing things that look really advanced. Is learning HTML and CSS a good choice to start? Would I be hired for a job knowing only HTML and CSS?
@Shinnogo
@Shinnogo 3 ай бұрын
That's called Front End developer if you want to look into it more. I think it may need some JavaScript too, but I think most of it is CSS and HTML. I would look at a channel called Kevin Powell if you wanna learn more CSS. Don't know how the job market side of it is though.. I know it's a very popular position among coding so loooots of applications will need to be made when trying to get in most likely.
@cheekypigg
@cheekypigg 3 ай бұрын
Thank you!!!
@vladimir_dev
@vladimir_dev 3 ай бұрын
More awesomesauce! :)
@kickbuttowsk2i
@kickbuttowsk2i 3 ай бұрын
but can't we just apply flex on "actions" and call it a day?
@nclsDesign
@nclsDesign 3 ай бұрын
I used this once but totally forgot about it
@aadras
@aadras 3 ай бұрын
where was this ; -;
@vinhcomputer
@vinhcomputer 3 ай бұрын
Have fun refactoring right now :D
@vanechka222
@vanechka222 3 ай бұрын
Cool, but why not just remove the div?
@xhilaJ
@xhilaJ 3 ай бұрын
this is kinda useful thanks
@ChadFrontend
@ChadFrontend 3 ай бұрын
Chad Frontend approved ✅
@DevNhaX7901
@DevNhaX7901 3 ай бұрын
yeah, super handy.
@solaarsslave
@solaarsslave 3 ай бұрын
the fuq are they not naming it someting like flex-ignore, or something that actually makes sense :D display: contents? Never understood.
@younesdeveloper
@younesdeveloper 3 ай бұрын
boom, i love it
@0xAndy
@0xAndy 3 ай бұрын
Holy shit! sub-flex?
@WesBos
@WesBos 3 ай бұрын
thats a good way to put it!
@matthewallenblack
@matthewallenblack 3 ай бұрын
Could it even be sub-sub-flex in you put that display property on the "grandchild" elements?
@iamkevinricher
@iamkevinricher 3 ай бұрын
Why is your body set to grid? 🤔
@WesBos
@WesBos 3 ай бұрын
So I can put this nav in the middle of the document - not uncommon to grid the body for layouts though.
@H_reugo
@H_reugo 3 ай бұрын
WHAAT, that is super helpfull
@bmehder
@bmehder 3 ай бұрын
Bravo!
@sjoerdvermeijden
@sjoerdvermeijden 3 ай бұрын
Why not just make .actions a flex container too and put flex-grow on the search bar. That way you can still apply styles to .actions.
@WesBos
@WesBos 3 ай бұрын
That works here too - but not in every case, especially with wrapping and space between/around alignment. The point here isn’t that this layout is impossible without it, it’s to understand how it works because you’ll be in spots where you’ll need it
@SaurabhSrivastava-i1q
@SaurabhSrivastava-i1q 3 ай бұрын
So basically, Browser developers are building awesome things into the browser for us peasants FE engineers to use, yet we don't use them because docs are boring to read!
@guygryphon
@guygryphon 3 ай бұрын
Woah 🤯
@megamind452
@megamind452 3 ай бұрын
I used to think it as an illegal css property. Because it is so powerful
@GustavoDiaz93
@GustavoDiaz93 3 ай бұрын
Nice
@johncasper5948
@johncasper5948 3 ай бұрын
Woah!
@kissu_io
@kissu_io 3 ай бұрын
The thumbnail tho..
@qwertz3813
@qwertz3813 3 ай бұрын
cool
@scottonanski4173
@scottonanski4173 2 ай бұрын
It would be even better is it didn't do that in the first place.
@dhunsworth
@dhunsworth 3 ай бұрын
Why not just remove the div?
@DavideMaiolo
@DavideMaiolo 3 ай бұрын
right ? i am still trying to find an example why you shouldnt want to just remove the div, since you loose all styling ability. Maybe someone could explain
@pnlqlf4057
@pnlqlf4057 3 ай бұрын
I have yet to test it but sometimes I want to wrap certain inputs with a without altering the css. I think it might be good solution for that
@chase-bank
@chase-bank 3 ай бұрын
​@@DavideMaiolo I can think of dozens of scenarios where a wrapper is necessary but the accessibility limitations of this trick isn't an option for most of them. But in this case, we could assume it's a search component encapsulated in a wrapping div, and changing that internal markup may not be an option. Also, in a different media query, perhaps that wrapper div is even still serving a styling purpose.
@Nightizm
@Nightizm 3 ай бұрын
coooool!!!
@bollywoodkol783
@bollywoodkol783 3 ай бұрын
😮
@ShiNijuuAKL
@ShiNijuuAKL 3 ай бұрын
magic
@megafoxatron3rd521
@megafoxatron3rd521 3 ай бұрын
question, does it matter if i can have AI write css now?
@heavenaldrico
@heavenaldrico 3 ай бұрын
DAMN
@p_o_z_e
@p_o_z_e 3 ай бұрын
fuck me, this is super handy!
@dieGRUVE
@dieGRUVE 3 ай бұрын
wait, what?!
@5ulo
@5ulo 3 ай бұрын
Super handy but not accessible, which is a big no-no
@_BonsaiBen
@_BonsaiBen 3 ай бұрын
Holy fucking shit
@cats4president
@cats4president 3 ай бұрын
🤯
@aufdem2
@aufdem2 3 ай бұрын
Uhhhhh..... 😅
@abiiranathan
@abiiranathan 3 ай бұрын
Fck. I have code to refactor
@pu239
@pu239 Ай бұрын
How did you just find out about it? You've never cycled through all the options in the dev tools autocomplete menu after display? Weird clickbait, you don't need to lie like that
@NormCantoral
@NormCantoral 2 ай бұрын
women be like... repeat that part about displaying contents to make flex grow things... again... for posterity of course
@lemomar
@lemomar 3 ай бұрын
This is a huge timesaver wow And of course it’s supported by Tailwind so I’ll be sure to use this from now on This is such a common use case
@WesBos
@WesBos 3 ай бұрын
yep, just `contents` in tailwind!
@lemomar
@lemomar 3 ай бұрын
@@WesBos Indeed, it’s great!
@KonstantinDankov
@KonstantinDankov 3 ай бұрын
What does supported by tailwind even mean? Tailwind is a way to write css, everything in css is “supported” by tailwind. You just have to learn yet another dsl ….
@WesBos
@WesBos 3 ай бұрын
​@@KonstantinDankov I think he means that there is a tailwind class for it - there is a bunch of new stuff that tailwind doesn't "support" so you gotta duck out of tailwind and write regular CSS
@zzkevinlim
@zzkevinlim 3 ай бұрын
meh, just make .actions flex, same thing
@hyperprotagonist
@hyperprotagonist 3 ай бұрын
I feel sorry for those living under a rock. By rock I mean shadcn. 😂
@SK_Covers
@SK_Covers 3 ай бұрын
😮😮😮 Me using div flex for medium screen and flex column for smaller screen 🥲🥲🥲 This is lit 💯💯💯
@SebastianMares
@SebastianMares 3 ай бұрын
🤯
How to take control of Flexbox
16:01
Kevin Powell
Рет қаралды 147 М.
Custom dropdowns just got a whole lot easier (finally!)
4:33
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Stop using position absolute - use CSS Grid stacking!
4:42
Responsive CSS Flexbox layout 8 .|Amin coding
5:06
Amin Coding
Рет қаралды 16 М.
This CSS Backlight Effect is so damn cool!
3:18
Wes Bos
Рет қаралды 16 М.
The secret to mastering CSS layouts
17:11
Kevin Powell
Рет қаралды 297 М.
A flexbox trick to improve text wrapping
5:02
Kevin Powell
Рет қаралды 227 М.
Learn CSS Subgrid in 14 minutes
14:19
Slaying The Dragon
Рет қаралды 93 М.
Why did OpenAI move from Next.js to Remix?
10:41
Wes Bos
Рет қаралды 202 М.
Easy and more consistent layouts using subgrid
8:01
Kevin Powell
Рет қаралды 49 М.
Learn CSS flexbox in 10 minutes! 💪
10:01
Bro Code
Рет қаралды 199 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН