Use this instead of media queries or container queries

  Рет қаралды 40,960

Kevin Powell

Kevin Powell

Күн бұрын

Пікірлер: 95
9 ай бұрын
It reminds me of writing a more complex RegEx. At the time you write it, you know what you're doing, but one month later you just think WTF!
@KevinPowell
@KevinPowell 9 ай бұрын
The nice thing with this is, if you set it up well, it's easy to update/change values with the custom properties, whereas regex one small change and half of your text vanishes 😅
@florentd.5817
@florentd.5817 9 ай бұрын
Regex is simplier than css ! 😂
@rossclutterbuck1060
@rossclutterbuck1060 9 ай бұрын
@@florentd.5817 then you really suck at CSS
@florentd.5817
@florentd.5817 9 ай бұрын
@@rossclutterbuck1060 i know, i know... that why so many people use ready made css ( frameworks ).
@2eanimation
@2eanimation 9 ай бұрын
​@@rossclutterbuck1060 I'm comfortable writing both regex and CSS. Although this is comparing apples and cars as they have very different use-cases, Regex is WAY easier. Exhibit A: Regex docs are a 2-5 min read(type 'man regex' or 'python -c "import re; help(re)" ' in shell). Might take you some time to read and digest CSS docs :)
@stevelam1315
@stevelam1315 7 ай бұрын
I like this calc so that I can speak in tongue now and the computer or AI still loves to compute it. Thank you Kevin. For side note, I don't skip watching youtube ads on your videos and let them run to put $$ into your pocket.
@taylorsabbag6962
@taylorsabbag6962 9 ай бұрын
Looked into Heydon Pickering and Andy Bell's Every Layout because of you, and I can't thank you enough. Currently completing my full-stack SWE bootcamp, and CSS felt like my weakness because I hated BEM (the methodology they teach us). I don't like the tight coupling between HTML and CSS of BEM nor the utility-only methods of Tailwind. The combination from CUBE CSS and Every Layout of these kinds of "algorithmic" layouts and Tailwind for exceptions and smaller styling concerns is exactly the approach that best agrees with my sensibilities. I.e. I want designs that are completely responsive and handle themselves with minimal modular CSS. Anyways, I love these kinds of approaches to global, layout-driven, algorithmic CSS. It makes more sense for the modern web and its fragmented experiences.
@LukeDorny
@LukeDorny 9 ай бұрын
Omg. This couldn’t have come out at a better time. Thanks for this, Kevin. Next, can you cover grids without breakpoints when one of the children spans two cols or two rows as a featured child? That’d be awesome, because at small sizes this breaks/overflows.
@JoseRodriguez-rx4ck
@JoseRodriguez-rx4ck 9 ай бұрын
WTF man, I was about to do the same comment, about timing, and a suggestion about a featured child with a two columns span, hahaha, so weird.
@Dorchwoods
@Dorchwoods 9 ай бұрын
This is neat for sure. I'll probably stick to media queries and container queries but i love the creativity and uniqueness of this approach. In my opinion, things this are much more useful when you write out an explanation in the css comments above or below. The way you wrote out the calc function with real values is super useful information for any developers coming into this file making changes later
@RobBulmahn
@RobBulmahn 9 ай бұрын
Same. It's neat to know it exists and how it works, but I wholeheartedly disagree with Kevin on readability/maintainability. If this is for your own personal site, then fine, but if you're working on a project with others, or have to hand this off to others to maintain, I can guarantee they will all hate you.
@alanbloom20
@alanbloom20 9 ай бұрын
A really nice pattern. Albeit with more complexity, a three segment break point is possible by nesting more min/max elements. Has been a very useful method for me for a long time before container queries were available. As for readability, I agree with your previous video. We can’t shy away from these methods just because they are challenging concepts for some other people.
@clevermissfox
@clevermissfox 8 ай бұрын
We need a shirt championing the min() function!!! I adore it
@Clay286
@Clay286 8 ай бұрын
Thank you a lot! Though it seems to be a bit comlicated, it's a great training in creativity and flexible mind!
@CarlosHernandez101400
@CarlosHernandez101400 6 ай бұрын
Coming back to review this video and I have to point out a minor drawback to the grid approach: You get either one column, or your set number of columns, nothing in between.
@SoreBrain
@SoreBrain 9 ай бұрын
This is exactly what I needed in my code. The css variables keep my svelte component very composable. I knew there was a way but I wasn't getting there myself without a lot uglier code. Thank you Kevin!
@AndrleJan
@AndrleJan 9 ай бұрын
Yah, I am also the maths guy, so I like to use these approaches. I have just one note: for computation (and any internal) variable, I would use the JS private notation `--_breakpoint`/`--_column-size`. Or maybe double underscore, as I sometimes use default value approach `--_column-count: var(--column-count, 2); /* sets num of cols when enough spase */`.
@airixxxx
@airixxxx 7 ай бұрын
Sometimes is better to go for the simpler approach than the fancy one.
@bj-earn
@bj-earn 9 ай бұрын
I did use something comparable on a slightly different usecase where I wanted to set a maximum number of columns. So when there is enough space the grid should not display more then the maximum number of columns defined. On smaller screens it just shrinks down to whatever it has room for. grid-template-columns: repeat( auto-fit, minmax( max( var(--min-col-width), calc( (100% - (var(--gap) * 2) ) / var(--max-cols) ) ), 1fr)); I think the --min-col-width should contain the inner padding of a column.
@pappapez
@pappapez 8 ай бұрын
This is great stuff! I think that if you use some library to write css for you, some of the calculations may fit there and you can keep the calc() calls to deal with things only css can do (like percentages, fr, and such).
@henklangeveld5463
@henklangeveld5463 8 ай бұрын
Hi Kevin, I always love your content. Your grid breakpoint calculation could however be much simpler: Just add column-size and gap together, multiply by column-count then subtract one gap from that total (because, as you say, you have one less gaps than columns).
@mohamedamineboukraia9317
@mohamedamineboukraia9317 9 ай бұрын
I really like the fact that you come up with these unorthodox ways of styling but from a reactJs developer perspective it's hard for me to focus too much on css ways of getting things done or search for the most elegant way to handle a certain situation I'd rather go with fastest way plus I feel I can get the same results thanx to Css-in-JS, but I salute you for your creativity and honestly you're the one who helped fall in love with css, GJ
@utoddl
@utoddl 9 ай бұрын
I like this much more than media queries. Math is not scary.
@BGdev305
@BGdev305 9 ай бұрын
Except if it's trig! In this specific video of Kevin's I just don't see how this is easier than container queries.
@einatblackrose
@einatblackrose 9 ай бұрын
This is probably exactly the tutorial I need now, yet I didn't manage to follow and comprehend (well, my math sucks). Thanks for making the effort to explain this. Maybe I'll get to it one day...
@KevinPowell
@KevinPowell 9 ай бұрын
It's definitely a little strange. I had to pause a few times to try and explain it properly, so sorry if it wasn't clear enough but I was wrapping my mind around it too, lol.
@uncleelder4922
@uncleelder4922 9 ай бұрын
Cool. This is the kind of CSS that you stick in a library. In the future, you'll remember what it does, but forget how it does it.😂
@Alex29196
@Alex29196 9 ай бұрын
Try Obsidian, helps me a lot
@daveturnbull7221
@daveturnbull7221 9 ай бұрын
I'm worried...this all actually made sense to me, even the min and max inside the minmax. I do believe some of your teaching is actually starting to sink into this dense skull of mine Kevin 🤣
@Azhtyhx
@Azhtyhx 9 ай бұрын
I'd say this is actual responsive css, whereas media queries is the hack method. It doesn't look strange or weird, but elegant in its complexity. Great video!
@trinkel8
@trinkel8 9 ай бұрын
Yeah, love this idea. Is it difficult to read? Maybe, but we also want CSS to be a programing language. It's also a great use case for comments. I may not be able to make this stuff up, but I can understand it once I take the time to tear it down. If this method isn't for you, no one is forcing you to use it. I think I would use a class for the sidebar instead of pseudo so I can have it left or right without changing the guts of the CSS. (I haven't totally thought that through, so no hate.) I'm heading straight over to CodePen to pin these suckers. Hopefully I'll get a chance to use them somewhere.
@limbo3545
@limbo3545 9 ай бұрын
I copy-paste it and never think about it ever again. Thank you so much!
@luckyduckystudios5709
@luckyduckystudios5709 9 ай бұрын
I always learn from your stuff. Thanks for the great content!🎉
@sovereignlivingsoul
@sovereignlivingsoul 9 ай бұрын
i am wondering how you get into the mindset of coming up with these methods, i find them very advanced in conception, after your video where you introduced this concept, i have been trying to incorporate them in my designs, my first attempt wasn't bad, i am still getting used to using custom properties so designing my layout based on them is going to be a bit of a challenge, but i will accept it, i think you got a great thing with this, it is just a matter of finding the right combinations.
@deltaclub42
@deltaclub42 7 ай бұрын
Best tutorial about how make the other devs in the team hate you. It’s a very clever solution tho
@e11world
@e11world 9 ай бұрын
This is definitely a fun one. Kinda messed up since I'm not used to this much math but ok once you dissect it. I wonder if you have a similar approach to spacing and font sizes (I used something with min or max but always felt hacky.
@laura-ashleekotelman2088
@laura-ashleekotelman2088 8 ай бұрын
I really like this way of working with the desired widths of the content first, rather than starting with browser width. I am getting a little confused on some of the numbers in the calculation. Can you explain in a bit more detail why are we multiplying this calculation times 9999?
@Turabbo
@Turabbo 9 ай бұрын
Looks like the sort of thing I'd spend hours formatting into a beautiful user-friendly mixin with validation and stuff. Just to end up being the only person in my company that uses it lol
@ivanshi4258
@ivanshi4258 8 ай бұрын
Thank you for your video :D which gives me a new thought to layout. But I still get confused about the "--column-size" variables, I think it might be "calc((100% - var(--gap) * (var(--column-count) - 1)) / var(--column-count))", Substract all gaps and then divided by count of columns. if divided first, i cannot get the same original column size as the calculation of "breakpoint".🤥
@gromit1768
@gromit1768 9 ай бұрын
I'm still hoping that one day you'll write a book. I'd definetly buy it! :)
@nomadshiba
@nomadshiba 9 ай бұрын
if @container allowed you to select container itself, we could have made this easier to work with by using @container style(), by using the custom-properties as mixins
@LokiDaFerret
@LokiDaFerret 9 ай бұрын
All of your order of operation problems go away if you create more custom variables. A custom variable like --breakpoint-count makes your code much more readable and far more maintainable. The moral of the story is just because you can write everything with one line of CSS doesn't mean you should.
@SilvesterBoots
@SilvesterBoots 7 ай бұрын
I'll agree, that complex operations should be shortened with readable variables.
@marlngomz
@marlngomz 6 ай бұрын
Just curious ... Is the grid solution really solving the same issue as the flex solution? Isn't the grid solution fixing an amount of columns problem, and the flex solution a difference in when something goes on a row (differences in columns' size rate)?
@flx76
@flx76 9 ай бұрын
A use-case I came across recently was to go from 1 column to 2 columns to 4 columns depending on the available space. Can you think of a good way to add such an intermediate step using this technique?
@yellowbonbon1
@yellowbonbon1 9 ай бұрын
Could you have a separated video to explain the "*999" or "* -999* ? That's very confusing. Thanks ahead.
@ivanshi4258
@ivanshi4258 8 ай бұрын
I think "*999" is just a flag which indicates whether 100% is greater than the "breakpoint" under the css "max()" func. if not using "*999" and your parent size being just a little narrower than "breakpoint", "max()" func will still choose the calculated column size instead of 100% of the outer "min()" func.
@felipefernandes9642
@felipefernandes9642 9 ай бұрын
What a beautiful "Hello World"! What font family are you using?
@khalil_art
@khalil_art 9 ай бұрын
What if we wanted a minimum of two columns on mobile and 4 on large screens?! I think that would be the best layout to make.
@JawsoneJason
@JawsoneJason 9 ай бұрын
Super cool, but I would never use this in a team setting.
@alvaroprietovideos
@alvaroprietovideos 9 ай бұрын
This video is amazing 🔝
@мультифора
@мультифора 9 ай бұрын
this is super cool, i hate media queries, ill use this instead
@RandomGeometryDashStuff
@RandomGeometryDashStuff 9 ай бұрын
05:20 are outer parentheses in line 14 needed?
@MartijnSnapper
@MartijnSnapper 9 ай бұрын
Maybe a slightly different approach, I want to set the maximum number of columns. For this I use the clamp() function. --cols: 3; --gap: 1rem; --min-width: 20ch; grid-template-columns: repeat( auto-fill, minmax(clamp(var(--min-width), 100% / var(--cols) - var(--gap), 100%), 1fr) );
@Alex-fm9oj
@Alex-fm9oj 9 ай бұрын
It looks like a cool thing that you shouldn't use anywhere other than your own projects.
@CasparDue
@CasparDue 9 ай бұрын
Maybe clamp would work in the minmax part instead of min and max? minmax(clamp(var(--column-size), (100% - var(--breakpoint)) * -999 , 100%), 1fr)
@farzadmf
@farzadmf 9 ай бұрын
This seems like "nice only for the first person coming up with this solution" thing; I find this very hard to maintain in the long term.
@JoepKockelkorn
@JoepKockelkorn 9 ай бұрын
I agree
@axMf3qTI
@axMf3qTI 9 ай бұрын
You know what was hard to maintain? building layouts with floats and having browser incompatibility. This is a breeze.
@olivierheimerdinger1629
@olivierheimerdinger1629 9 ай бұрын
Wouaou so great!!!
@boby4751
@boby4751 9 ай бұрын
I do not see the link to download the code, or is it just me?
@CarlosHernandez101400
@CarlosHernandez101400 9 ай бұрын
To me, your code is as "complicated" as Shakespear-style English. Sure, it looks complicated, but if you take the time to look thru it, it actually is quite readable and highly functional (a Sonnete might make you more lucky with the ladies than, "You must be tired, because you've been running on my mind all day"). Needing to figure out different breakpoints to set up MQs vs changing 1 or 2 variables is worth typing out the Calc functions. Thanks, Kevin!
@crazyingenieur3277
@crazyingenieur3277 9 ай бұрын
I think you made a math mistake at 13:05... your formula should be .... + gap * (column_count - 1)... you put your parenthesis in the wrong place. And I think your column_size calc is also wrong... If you want to calculate the column size for each... you subtract all the gaps (gap * column_count) from 100% and then divide it by the column count.
@dj10schannel
@dj10schannel 9 ай бұрын
Awesome
@fray-roe1715
@fray-roe1715 9 ай бұрын
Do you have a Udemy course?
@ricardodasilva9241
@ricardodasilva9241 9 ай бұрын
Isn't this the same as the "holy albatross" pattern and variants "unholy" and "devil"
@EvanEdwards
@EvanEdwards 9 ай бұрын
/* Again, there is a simple solution to explaining any complicated parts of CSS. */
@kevbonett
@kevbonett 9 ай бұрын
Without watching the whole video, I'm guessing you're using the "sidebar" Flexbox idea from Every Layout, and CSS Grid "auto-fit" feature? Both are great!
@KevinPowell
@KevinPowell 9 ай бұрын
sidebar is a variation of what they did, but stepped up a little bit so that it's based on the width of the larger area, rather than the parent, and then I use that same technique within auto-fit afterwards :)
@kevbonett
@kevbonett 9 ай бұрын
@@KevinPowell yes, I watched the video in full after adding my comment... very cool.
@tauhidxahmed
@tauhidxahmed 9 ай бұрын
king
@TheCârtiță
@TheCârtiță 9 ай бұрын
Lots of math creating the variables. I'll wrap my head around that
@Henry-q5g1e
@Henry-q5g1e 9 ай бұрын
M * X dont need to be wrapped like (M * X) your big calc does the latter..
@BGdev305
@BGdev305 9 ай бұрын
Sorry, I just don't.. or better yet, can't see how this is easier to accomplish then with container queries. Yes, compared to the amount of math, etc. used in this video, I don't mind using more lines of code to accomplish this using media queries. Compared to trying to figure out the science of CSS you used in this video I'd do some display:none first.. sorry.
@czerskip
@czerskip 9 ай бұрын
People who call those beautiful solutions hacks should go back in time twenty something years and try coding for IE 5.5 for Mac 😅
@johansmith2840
@johansmith2840 9 ай бұрын
it's just css's of scripting(functions )
@hiddensinger2630
@hiddensinger2630 8 ай бұрын
Super calculation, but its difficult for me
@ghsnoori
@ghsnoori 3 ай бұрын
I replaced flex-basis: calc(((var(--main-min-width) - (100% - var(--sidebar-size) - var(--gap))) * 9999)); width this one: flex-basis: var(--main-min-width); and it worked the same! Is there any difference in work?
@erickdavid4257
@erickdavid4257 9 ай бұрын
my head hurts
@OleksandrPanteli
@OleksandrPanteli 9 ай бұрын
good to know but definitely NOT gonna use it in production
@selvaganapathia5049
@selvaganapathia5049 9 ай бұрын
Hi...
@MatthewKennedyUK
@MatthewKennedyUK 8 ай бұрын
Don’t watch this if you’re on your first week into css.
@eqlipt
@eqlipt 8 ай бұрын
I'd rather stick with media queries. This seems too complicated, and I don't see any potential benefits over @media.
@ajitmali3821
@ajitmali3821 9 ай бұрын
css is becoming more and more programming language😅
@porknwithbill
@porknwithbill 9 ай бұрын
This is way over complicated
The background values no one knows about
15:28
Kevin Powell
Рет қаралды 42 М.
Master HTML Forms in 30 Minutes: Essential Input Types Explained
31:14
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 324 МЛН
HELP!!!
00:46
Natan por Aí
Рет қаралды 54 МЛН
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН
Random Emoji Beatbox Challenge #beatbox #tiktok
00:47
BeatboxJCOP
Рет қаралды 61 МЛН
Container Queries are going to change how we make layouts
24:24
Kevin Powell
Рет қаралды 176 М.
ChatGPT-o1 Created A Programming Language...
19:45
Conner Ardman
Рет қаралды 127 М.
A new approach to container and wrapper classes
25:27
Kevin Powell
Рет қаралды 266 М.
What is LLVM: How It Powers Modern Compilers and Optimizes Code
6:31
The Coding Gopher
Рет қаралды 7 М.
How is this Website so fast!?
13:39
Wes Bos
Рет қаралды 952 М.
Why Are Open Source Alternatives So Bad?
13:06
Eric Murphy
Рет қаралды 672 М.
Why I Quit Netflix
7:11
ThePrimeagen
Рет қаралды 517 М.
My top 5 most popular front-end tips
22:07
Kevin Powell
Рет қаралды 56 М.
Subgrid & Container Queries change how we can create layouts
21:08
Kevin Powell
Рет қаралды 77 М.
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 324 МЛН