min(), max(), and clamp() are CSS magic!

Поділитися
Вставка
  • Опубліковано 11 гру 2024

КОМЕНТАРІ • 307

  • @MelTurner
    @MelTurner 4 роки тому +250

    Maybe important to mention that SCSS can get confused if it encounters a CSS min or max function because SASS has conflicting functions. For example min(200px, 80%) will cause a SASS units error. The trick is to capitalize: Min and Max so they are ignored by SASS (CSS is case insensitive)

  • @rc91249
    @rc91249 4 роки тому +143

    Whenever I have a issue with CSS or just want to learn a new property. I’m always so happy when I can find a video from Kevin explaining the subject! His a CSS magician ✨

    • @shaikhabdulazim6908
      @shaikhabdulazim6908 3 роки тому +3

      He is a legend 👌

    • @astrodas1910
      @astrodas1910 3 роки тому +2

      So true! I was thinking, it'd be great to have a way to make font-size responsive with simple code. Next time I open youtube BOOM! This video appeared on my home page :)

  • @mintran
    @mintran 4 роки тому +258

    I thought I was pretty good at CSS until I discovered your channel.

    • @coced
      @coced 4 роки тому +16

      Subscribe to Kevin for your regular dose of Dunning-Kruger effect

    • @proudyy
      @proudyy 2 роки тому

      Actually same. My css is quite messy but still at a point sorta advanced. I just have huge problems with responsibility and the entire layout which is basic stuff. xD
      So to be honest, I am still quite a beginner. I got my way although already into custom box-shadows, linear and radial gradients as such, and different color units (rgb, hex, ...).

    • @lewisone
      @lewisone Рік тому +3

      Right. I felt I was a rockstar until I found Kevin telling me that I barely know 20% of the things I need to know. Ego drop.

    • @Bean-kw2xp
      @Bean-kw2xp Рік тому

      same

  • @ukyo6195
    @ukyo6195 4 роки тому +66

    Works in all modern Browser:
    font-size: calc([minimum size] + ([maximum size] - [minimum size]) * ((100vw - [minimum viewport width]) / ([maximum viewport width] - [minimum viewport width])));
    e. g.
    font-size: calc(2.25rem + (36 - 20) * ((100vw - 300px) / (1600 - 300)));

    • @noinfo9941
      @noinfo9941 4 роки тому +9

      I use this one too after reading the article from css-tricks "The Math of CSS locks".

    • @samuelgoncalves5616
      @samuelgoncalves5616 4 роки тому +6

      Your code is wrong, should be: font-size: calc(20 + (36 - 20) * ((100vw - 300px) / (1600 - 300px)))

    • @samuelgoncalves5616
      @samuelgoncalves5616 4 роки тому

      But is a great tip, thanks

    • @ukyo6195
      @ukyo6195 4 роки тому +5

      @@samuelgoncalves5616 does it not automatically use px if a unit is not set, I’m not sure. Otherwise thanks for the correction, I’ll test it. 👍

    • @nikilragav
      @nikilragav 4 роки тому

      Ya that's what I used to do :)

  • @crstfrdrnt
    @crstfrdrnt 4 роки тому +20

    I'm two weeks into seriously learning html and CSS and keep coming to your videos because they're awesome. You are one great teacher

    • @loganligas8418
      @loganligas8418 2 роки тому

      How are you doing now? Hope all is well. :)

  • @degagnemarc
    @degagnemarc 4 роки тому +36

    Just love it!
    Great for replacing some media query.
    .row { width: clamp( min( 95%, 414px ), 80%, 1200px ); }
    Thanks Kevin for making us better devs.

    • @guillermodanielmazzarigiov1768
      @guillermodanielmazzarigiov1768 2 роки тому +1

      Could you please explain what you did in that codeline 😂😂😂 I'm new to this

    • @the_meaning_of_love
      @the_meaning_of_love 2 роки тому +14

      @@guillermodanielmazzarigiov1768 width of:
      - It doesn’t matter how big the screen is, it will never grow over 1.200 px (max-width)
      - When the screen size is small enough that the 80% of the container is smaller than 1200px (for example a screen of 1240px), it will be 80% of the width of the container.
      - And when the screen size is really small (as in mobile devices), the minimum size the element is going to get is 414px or 95% of the container, whatever is smaller.
      Basically this line is defining what’s the minimum width of the element with a min value (95% or 414px, whatever is smaller), what’s the preferred size of the element with an 80% of the container width, and what’s the maximum size of the element with a fixed value in pixels (1200)

    • @dexter3943
      @dexter3943 2 роки тому

      what would be the media query values for this?

    • @guillermodanielmazzarigiov1768
      @guillermodanielmazzarigiov1768 2 роки тому +2

      @@the_meaning_of_love I hadn't seen your answer, thanks man! Btw, this is brilliant, and if I would have read your answer 2 weeks ago I wouldn't have understand it anyway lol, this made me very happy, to see how much I've learned in only 2 weeks 😀

    • @irfansaeedkhan7242
      @irfansaeedkhan7242 2 роки тому +1

      you are geniius, can i get your github repo or linkedin profile for more pro stuff, like a project that covers all these standards and we can copy from here when making new project, i already use mixins for media queries and fonts for reusability but you share some next level thing for me in a single line

  • @GineetMehta
    @GineetMehta 4 роки тому +9

    I am absolutely baffled at the quality of content you put out, Kevin.
    Direct, crystal clear, practical videos of everything relevant. No BS.
    I have been working as a frontend developer for around 14 months now, and I stumbled on your channel while searching for Intersection Observers.
    Love the content! Subscribed to the channel and will sign up for the newsletter too.
    Thank you for your time and effort in giving back to the community. Much appreciated.

  • @gosnooky
    @gosnooky 4 роки тому +20

    Really enjoy your videos. I spent most of my career from the 90's onward doing systems programming in C, C++ and Java, but now that the money is in front end, I'm digging all these modern toys and tooling.

  • @joeldcanfield_spinhead
    @joeldcanfield_spinhead 4 роки тому +77

    This, I've dreamt about for so so long. Not back in '94 when I started coding HTML3.2, but it's definitely been years.

    • @Colstonewall
      @Colstonewall 4 роки тому +6

      WOW! I had no idea there was anything like HTML around that time ('94). I didn't even know the Internet existed until about 1997. You've been at it a while Joel!

    • @joeldcanfield_spinhead
      @joeldcanfield_spinhead 4 роки тому +35

      @@Colstonewall Sheesh; I was LATE to the game. The first graphical browser, Mosaic, was released in '93 and other folks were already making stuff I envied.
      Now, imagine the years from 94 to 99, the long wait for HTML4. Oh, and the same wait for CSS to be widely supported by both browsers [yeah, 'both':Netscape Navigator and Internet Explorer because, c'mon, there were like 3 people using Opera and 12 using Konqueror.]
      More old man rant: this was also all delivered over modems at speeds of 28.8kb. A 2:36-long mp3 would take 6+ minutes to download. A video would take about ten thousand years.

    • @Colstonewall
      @Colstonewall 4 роки тому +5

      @@joeldcanfield_spinhead Amazing. How I wish I had gotten into the game at least in the late 90's or early 2000's much less when you did.
      You're a Legend, Joel!

    • @KevinPowell
      @KevinPowell  4 роки тому +34

      Same. I did it on and off as a hobby since the late 90s. Sort of wish I got into it full-time earlier! Though I don't miss table based layouts 😂

    • @joeldcanfield_spinhead
      @joeldcanfield_spinhead 4 роки тому +5

      @@KevinPowell No kidding. I stumbled across a horror yesterday: I'm redesigning my author website and went to take one last look at two of my favorite authors' sites.
      I keep forgetting that one of them, a famous mystery writer, has a website that was built with tables in 1998 (no exaggeration) and nothing but the content has been updated since.

  • @AllElectronicsGr
    @AllElectronicsGr 4 роки тому +64

    Your channel is sooo nice !

  •  4 роки тому +7

    Oh boy, I have an itch to go back to all my projects and use this! Thank you for such a clear explanation!

  • @markrm2212
    @markrm2212 4 роки тому +3

    Started coding websites professionally about two years back. Your videos really helped me out back then and still do today :)

  • @sherwan-yt
    @sherwan-yt 2 роки тому

    just before one hour, i wrote these line of code:
    width: max(min(10vw, 250px), 150px);
    because I had never heard from clamp() function!
    And after I watched your video, i realized that I can change this to clamp().
    thanks 👍

  • @stefanielis7052
    @stefanielis7052 4 роки тому

    OMG you SAVED ME. I'm just starting out but I wrote a webpage using TEN MEDIA QUERIES just to make the simple home page responsive and now with this I don't need a one. THANK YOU.

  • @shvideo1
    @shvideo1 3 роки тому +3

    Loved the usage of clamp() function with the font-size property and also learning about "vw" units. This is very handy and useful for web design. Thank you Kevin for this great video!

  • @codellyson
    @codellyson 2 роки тому +3

    I guess you can never know it all when it comes to CSS, thanks Kevin, you are doing a great job.

  • @codingtime3803
    @codingtime3803 3 роки тому +3

    I can't thank you enough kevin! I have learned so much about css and responsive design from your channel !! Your videos are gems!

  • @CipherosX
    @CipherosX 11 місяців тому +1

    It's interesting... something that maybe wasn't clafiried it's about with the 'min' and 'max' functions as well as the clamp one. One of the both values must be a relative unit such as percentage or viewport. With the clamp function this concept is applied on the 'ideal' value.
    Thanks Kevin for all the information you share!

  • @janelleschuh8424
    @janelleschuh8424 4 роки тому +4

    Kevin, thanks so much for the great video!! I've recently started my web development journey and your channel has been a tremendous help. So much so that as I'm practicing my skills via UA-cam video projects or Udemy course projects I'm not following along entirely and instead am inserting some of the new, cool CSS properties like clamp(). Thanks again!!!

  • @permanar_
    @permanar_ 3 роки тому +2

    I used vw unit pretty much for scaling font-sizing especially on a bigger.
    And on 12:15, I think it just not a good example of showing the sizing changes (except you use the computed tab -> font-size on the developer tools to inspect it). Because I believe it's actually changing but just not as much as we could see.
    And usually, you need to do a proportional ratio before using the vw unit for font-size.
    So my approach:
    100 * (value) / (viewport resolution)
    Let's say you have a Figma design with 1440px screen and there's a 18px value for a font-size on a subtitle.
    Then it just would like this: 100 * 18 / 1440 = 1.25.
    There you go with font-size: 1.25vw; and remember to use a @media query with min-width: 1440px.
    This will fixed this exact issue on 15:54.
    Just try to zoom out your browser or try resizing it on whatever resolution, it would stay THE SAME as 18px would work on 1440px screen, but it's actually on larger screen.
    I've rarely use vw on smaller screen or mobile devices. But this still could work whatever you want. Just remember changes your design "preferred" viewport value (maybe for 768px or something should work good).
    And just for a quick note: Sometimes this maybe not an always go-to solution because there's some monitor like ultra wide exist here.
    So yeah, you still need to double check everything.

    • @permanar_
      @permanar_ 3 роки тому

      Love to hear about others thought 💙
      What do you think guys?

  • @rodrigonoales
    @rodrigonoales 4 роки тому

    Amazing the amount of media queries you could potentially save to write ! Thanks for sharing

  • @alexisjones2045
    @alexisjones2045 3 роки тому

    Clamp seriously saved me on this website I'm building right now! Thanks so much.

  • @klutch4198
    @klutch4198 2 роки тому

    Absolute GOLD, font size responsiveness is just one of those things

  • @quietScooter
    @quietScooter Рік тому

    9:28 this is why I watch your content and nothing else, you don't fail to address the minor details!

  • @shhhpiderman8332
    @shhhpiderman8332 4 роки тому

    I couldn't figure out why people were adding in 1em/rem/px for the middle value. Thank you so much!

  • @spyrosp
    @spyrosp 4 роки тому +2

    Thank you Kevin! Always up-to-date 💪

  • @_jeffe04
    @_jeffe04 2 роки тому

    I tried max and it works perfectly with both desktop and mobile. It is what I was looking for. thanks!

  • @pulok9909
    @pulok9909 4 роки тому +1

    KP you are really awesome.I am learning CSS from your channel.It helps me a lot .May you live long.Recently I have become your fan.pls keep this good work up.

  • @mahdihashemi408
    @mahdihashemi408 Рік тому

    Thank you for your valuable and amazing videos. Your videos helped me a lot since I have started programming.

  • @petarkolev6928
    @petarkolev6928 3 роки тому

    Amazing video! Kevin, you just don't stop amazing me with each video, love your work!!!!

  • @patrickc.6183
    @patrickc.6183 4 роки тому +3

    Wow! This is literally something I could use ALL the time when writing CSS! Thanks 😁!

  • @ra9r
    @ra9r 4 роки тому

    I've only recently discovered your channel but DAMN, great content. Thank you and keep it coming!

  • @CB-fd4xu
    @CB-fd4xu 2 роки тому

    Finally! I've been enlightened. Thank you, Kevin.

  • @manantank
    @manantank 4 роки тому +3

    I used this a while ago and forgot about it. Thanks for reminding me. Also I didn't know you could give more than 2 values as arguments. That is pretty cool

  • @danielChibuogwu
    @danielChibuogwu 2 роки тому

    Thanks for this video Kevin, it was really really helpful😊

  • @deankinyua2365
    @deankinyua2365 10 місяців тому

    your channel is incredibly enllightening Kevin🤩

  • @jv18creator
    @jv18creator 4 роки тому +1

    O my goddddd... Man great video... Helped me a lot

  • @richmuratori9249
    @richmuratori9249 2 роки тому

    Thanks!

    • @KevinPowell
      @KevinPowell  2 роки тому

      Thank you *sooo* much, that's so generous of you. YT doesn't do anything extra to notify us for super chats, so I'm so sorry for the late reply.

  • @pagalpantipupun
    @pagalpantipupun 4 роки тому

    You won't believe I was looking for the exact thing today. Superb job. I am a new member of the house but I know there is a lot to learn.

  • @kokazo2009
    @kokazo2009 4 роки тому +4

    Thank you Kevin, I should definitely give it a try.
    Maybe you could show the computed section from the dev tools to see how font-size is changing on real time

    • @KeksBln
      @KeksBln 3 роки тому

      Good idea!

  • @Olderaccount17
    @Olderaccount17 Рік тому

    Thank you from Argentina, sir!

  • @iJimJones
    @iJimJones 4 роки тому +1

    I think this will come in handy for a use-case I am planning. It is a cemetery layout with grid blocks for gravesites in which the text within each block as one zooms in or out stays readable and appropriately sized. I need to couple this idea with displaying alternative text and more/less text based on size too (last name of burial only to full name to name and dates, for example).

  • @jamjam3448
    @jamjam3448 2 роки тому +1

    You're the best!!! Thanks so much

  • @TDavisOfficial
    @TDavisOfficial 3 роки тому

    Man, this just helped me out sooooooo much. Thank you, thank you, thank you!

  • @hanziel
    @hanziel 4 роки тому

    Ok, I think I need to binge your videos! Great CSS I've never seen before.

    • @KevinPowell
      @KevinPowell  4 роки тому

      Hope you enjoy my other videos :)

  • @nikhiltyagi1080
    @nikhiltyagi1080 4 роки тому

    One of the best and most useful videos you have ever made. Thanks a lot boss!!

  • @sivavijay1208
    @sivavijay1208 2 роки тому

    Yea, you hoped I learnt something. I learnt that I'm still a newbie in css whenever I see your channel

  • @aaron_phillips
    @aaron_phillips 3 роки тому

    Great video! This solved an issue I was having with a project I was working. :P

  • @taylorhorne1046
    @taylorhorne1046 3 роки тому

    you singlehandedly saved me from losing many hours of sleep last night. thank you king

  • @gabrielpena5829
    @gabrielpena5829 3 роки тому

    This video is amazing, I understood everything, THANK YOU

  • @sleepless83
    @sleepless83 2 роки тому

    You are awesome! I love your videos!

  • @singhravjot
    @singhravjot 2 роки тому

    Awesome explanation!

  • @slipoch6635
    @slipoch6635 4 роки тому

    it's css vars, or wasm. Completely supported without any fanfare whatsoever.
    Although I never use a max body size for a website, because then on 2k/4k screens it can end up looking awful.
    You could use clamp for column size in css grids for auto column sizing.
    Great video man!

  • @NicoMGrad
    @NicoMGrad 3 роки тому

    I think I've grown as designer since I met your channel. Thank you!?

  • @mtolin82
    @mtolin82 4 роки тому

    Wow. Thank you so much, you explain very well, so I have just subscribed!

  • @ritaravinsky8262
    @ritaravinsky8262 4 роки тому +1

    So cool, thank you Kevin

  • @cedricluck
    @cedricluck 4 роки тому +1

    One way to deal about the calc() solution is to put more weight in the static part of the calculation: instead of doing (1wv + 0.25rem) you should try (0.25vw + 1rem). Try to find a good balance and you will find the solution for your element to fit every screen width. Of course using clamp() is the best solution. I'm only using it on the WordPress DIVI theme builder because it doesn't allow the min() max() clamp() to be use on inline CSS snippets (which sucks btw!!)

  • @nevrgonnadnce
    @nevrgonnadnce Рік тому

    thank you for the video :) helped me with clamp alot.

  • @KlaudiusL
    @KlaudiusL 3 роки тому +1

    This video is a "Must Watch" before learn CSS

  • @nomadaxable
    @nomadaxable 3 роки тому

    Loved this video. Thanks for the good content.

  • @norbertperka9231
    @norbertperka9231 3 роки тому

    hi Kevin I recently found your channel and as I'm rookie to coding and building my own project I gave it a go to clamp() not only for font-size but also for margin and padding and I can say it works pretty good but I guess you already know about it :)

  • @travezripley
    @travezripley 4 роки тому

    The production is getting better Kev!!!

  • @JohnChristosMolura
    @JohnChristosMolura 4 роки тому

    Css is getting more exciting recently. I have not done much css work for a few years. On and off ... and each time i come here first to brush up on it. Thanks Kevin. Appreciate the videos.
    I have a request though. Could you make a video on using variable fonts reliably with fallbacks that make sense.

  • @nikilragav
    @nikilragav 4 роки тому +5

    I used to do this with calc with a linear equation although I don't remember exactly what it was something like calc(vw*some small number + 16px) so 16 is the min and it can get bigger from there

  • @-ct-celcomtechniques2566
    @-ct-celcomtechniques2566 Рік тому

    Best html/css teacher !

  • @j.almadhaji
    @j.almadhaji 4 роки тому

    Thank you
    Awesome content as always

  • @obscurecult
    @obscurecult 4 роки тому

    This is awesome, I'm gonna start using right now

  • @shayanfaghihi
    @shayanfaghihi 4 роки тому

    You are awesome! Thanks and big love from Iran :)

  • @burmesepotato447
    @burmesepotato447 4 роки тому +1

    Hi Kevin. I always learn something new from your vids and loved 'em! Can't wait to try clamp() on fonts. It'd be nice to see how to add proper fallbacks for them in next video :)

  • @BogdanAnghelina
    @BogdanAnghelina 4 роки тому +1

    Great job, man! It's a great content and your work is very helpful.
    I just start do write my new Wordpress theme and I use some of your videos for my CSS optimizations, tips and tricks.

  • @DerSolinski
    @DerSolinski 4 роки тому +3

    Oh... it wasn't fully supported until recently that explained a lot 🤣
    I'm so used to those functions and never really checked since they are fairly common in many programming languages...

  • @somtovitus
    @somtovitus 2 роки тому

    this is beautiful

  • @crooker2
    @crooker2 4 роки тому

    This is great. I was using your calc() dynamic font-size trick, but I think I will default to this and have the calc as the fallback until mass support.

  • @bazzle_brush
    @bazzle_brush 4 роки тому +1

    I've been waiting for this for years

  • @MelTurner
    @MelTurner 4 роки тому +2

    The only time more than 2 values is useful is when the values are custom properties being set somewhere else such as in a separate class. e.g. min(var(--prop1, 999), var(--prop2, 999), var(--prop3, 999)) where prop1/2/3 are only set by a specific class

  • @suav1148
    @suav1148 4 роки тому +4

    Great to know! I've always wished I could use min- and max- for font-sizes. Now I can use this! Thank you, Kevin!

  • @VasilyPavlik
    @VasilyPavlik 4 роки тому +1

    That is absolutely incredible cool!!! This is exactly what I need right now. Last and this week. Thank you so much. (Went to change 25% of my code).

  • @teal4069
    @teal4069 3 роки тому

    You taught me about clamp. Now I am a happy as a clam

  • @mariachaudhry4608
    @mariachaudhry4608 4 роки тому +4

    Your cheering voice is infectious

  • @mfranchi82
    @mfranchi82 3 роки тому

    What a Awesome videos, Kevin. Thanks for your explain

  • @csupra7
    @csupra7 4 роки тому +1

    Finally something that I've been searching since long time...

  • @_neuromanser_
    @_neuromanser_ 4 роки тому

    This is excellent, thanks! :D

  • @JacksBracket
    @JacksBracket 4 роки тому

    This.is.INCREDIBLE

  • @fabioiwano
    @fabioiwano 3 роки тому

    Hi, mr.Powell, I almost gave up using vw for text. It becomes unpredictable and terrible in ultrawide displays . You showed a very good way to use vw in text style. Thank you for this video.

    • @fabioiwano
      @fabioiwano 3 роки тому

      Hi Mr. Powell. Me again. Have you tried to apply clamp() in background property images? I tried to do it in an annoying alignment of a background with two images, with no much hope, but surprisingly, It saved me some lines of css and media queries. Didn't check compatibily in IOS Safari but it's working well actually. Well, thank you again.

  • @mohamaddadh3493
    @mohamaddadh3493 3 роки тому

    thank you so much teacher you are awesome man

  • @mikegogl
    @mikegogl 3 роки тому

    Thanks Kevin, I can always count on you.

  • @vivianmingaud7942
    @vivianmingaud7942 Рік тому

    Très grand merci à toi Kévin pour ton altruisme et ce partage 🙂

  • @ushanmithma9716
    @ushanmithma9716 4 роки тому

    Wow this is very useful sir, thank you very much 👌

  • @gracelamami
    @gracelamami 2 роки тому

    less than 5 min of the video I learn something nice

  • @JS-zm5se
    @JS-zm5se 3 роки тому

    Grateful I found this one.

  • @david-tracy
    @david-tracy 3 роки тому

    thank u man. I appreciate u

  • @justingiovanetti
    @justingiovanetti 4 роки тому

    Great video, cool stuff. Definitely a step in the right direction. Better than just relying on media queries.
    Regarding its application for font size, I’d argue though that a person’s field of view doesn’t change according to a view port or container size. That said, there are still specific use cases for being able to dial the font size on a granular level, but I believe it’s not nearly as many as people think, or nearly as significant as people perceive it to be.

  • @noco2605
    @noco2605 2 роки тому

    Thank you very much, very useful to know

  • @mariprugovechi
    @mariprugovechi 3 роки тому

    thanks for that! u r awesome! :)

  • @mohamed__gp5xz
    @mohamed__gp5xz Місяць тому

    Thanks Kevin!

  • @vahidjamshidnejad9525
    @vahidjamshidnejad9525 3 роки тому

    great,thank you

  • @andreiode8712
    @andreiode8712 4 роки тому

    Thank you sir....good explanation 🙏

  • @incorporealnuance
    @incorporealnuance 3 роки тому

    the thing I do with responsive font sizes before clamp, was too do calc(Xpx + Yvw), so that the pixel size was a sort of "soft" clamp of as low as the font could go, and would grow to fit & when zoom adjusted.

  • @bernattousfiga
    @bernattousfiga 3 роки тому

    Hi Kevin,
    Have you tried to set the html font size with clamp() and define all your site sizes (margins, font sizes, paddings...) with rem units? It makes all your web 100% responsive without using any media query!
    I used to redefine de html font size inside the media queries to scale the content according to the page width, but with clamp() I just don't need to do that anymore! Combined with the proper grid and flex properties, I'm able to have a nice responsive layout and get rid of media queries. Awesome!
    PS. Thanks a lot for all your content! I really appreciate your work. It's just brilliant and it helps a lot of people like me to become better frontend developers.

  • @catherinedesrochers
    @catherinedesrochers 4 роки тому

    You totally made my week... The ratio of like/dislike is impressive and deserved! This is an instant follow 👌