min-content, max-content, fit-content - intrinsic sizing with CSS

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 126

  • @heberccruz
    @heberccruz 2 года назад +34

    My favorite is fit-content, I usually put a max-width: fit-content; to solve the problem of changing after breaking

    • @warrenarnold
      @warrenarnold 2 года назад +11

      My favourite is chrome dev tools🐱
      I just try all of them until they fit my content

  • @zachjensz
    @zachjensz 2 года назад +68

    One could say we now have a wide coverage of width values

    • @crooker2
      @crooker2 2 года назад +7

      Yes. The breadth of this episode was expansive. 110vw in fact.

    • @easternadventures9978
      @easternadventures9978 2 года назад +1

      there's no min to the content kevin will teach us.

    • @warrenarnold
      @warrenarnold 2 года назад +2

      @@easternadventures9978 all three of you shut up, i will clamp your asses
      *Assets, meant graphical assets

  • @rs1mpower
    @rs1mpower 2 года назад +21

    I saw this thing like 1 day before I saw it on your channel but, man, Kevin, you really make me love CSS more and more. Even thought I'm on my path on self-taught web development and I'm just learning CSS, they way you explain it every single time amazes me. I'll be forever in your debts. Keep up the not good but the amazing work you do!

  • @atrus3823
    @atrus3823 2 года назад +7

    I made my first website in 1996 for a Quake clan I made with some friends in junior high. Back then, text was manipulated with the now defunct font tag, and anything layout related was mostly done with images and the background attribute. I was first introduced to CSS in the early 2000s when customizing my MySpace page. I didn't know it was CSS at the time. I started learning CSS in earnest in 2009, when Flash (I was a Flash developer) started to go belly-up. I consider myself a pretty advanced CSS user, but I don't really have time to keep up with all the changes since I went back to University and had 2 kids. This channel has been a really awesome way to just get little snippets of the most useful stuff to keep me in the loop. Thanks Kevin!

    • @KevinPowell
      @KevinPowell  2 года назад

      I remember those old days well! Glad I've helped you catch up, it's come a long way, lol

    • @atrus3823
      @atrus3823 2 года назад

      @dormie basne That would be interesting! I still have nightmares about the dreaded clearfix!

    • @rolandking507
      @rolandking507 2 года назад

      Unrelated question from a fellow Quake 1 player: What clan? :)

    • @atrus3823
      @atrus3823 2 года назад

      @@rolandking507 I can't even remember. It was not a successful one 🤣

  • @ryangreen7581
    @ryangreen7581 10 месяцев назад +6

    Kevin’s ability to teach concepts like CSS(coding) to an audience of unknown magnitude and absolutely excel at making it feel more understandable is mind blowing. Thank you!

  • @DanielLavedoniodeLima_DLL
    @DanielLavedoniodeLima_DLL 2 года назад +3

    I found the tutorial interesting, but right in the end you showed the clamp function and that was EXACTLY what I was looking for on my personal website, but didn't know existed. Thanks Kevin! You're awesome! As a Data Engineer/Backend Python Developer, I always learn new things with your videos.

    • @warrenarnold
      @warrenarnold 2 года назад

      Ok, I have your CV now, i will email you for a job offer

  • @SebastianZartner
    @SebastianZartner 2 года назад +2

    As always, fantastic video! Your examples and explanations always make it easy to understand what a specific CSS feature is doing and why you'd want to use it.

  • @spicario247
    @spicario247 2 года назад

    fr you just made me fall in love with css bc i strugle with it a lot and dont understent some things but you explain it soo goood and easy. This is the first time I fully understand width auto. you just made my day

  • @faisal_foyez
    @faisal_foyez 2 года назад +1

    I have learnt a lot about max-content, min-content and fit-content. Thanks Kevin😊.

  • @SaskiaStuder
    @SaskiaStuder 2 года назад

    You have no idea how much your videos mean to me. I have learned so so so much. Thank you for information that you share!!!

  • @petarkolev6928
    @petarkolev6928 2 года назад +1

    Amazing!!! This is so so useful to know!!!
    Thank you, Kevin ❤️

  • @alejandronieto576
    @alejandronieto576 Год назад

    Thank you from Buenos Aires! Very helpful!

  • @codehal
    @codehal Год назад

    Great Video❤

  • @books4all96
    @books4all96 5 месяцев назад

    Thank you Kevin Powell!! This tutorial was extremely concise and helpful!!!

  • @qchaxing2478
    @qchaxing2478 2 года назад

    Because people do not talk much about these values, I thought it was not good practice to use them.
    Let's start using them more often!
    Great video as always!

  • @CrazyCodingChannel
    @CrazyCodingChannel 2 года назад +1

    You always tell cool tricks, cool

  • @acidhauss7018
    @acidhauss7018 2 года назад

    I literally just used max-content today! Thought of the idea after learning fit-content a few months back from you its so helpful

  • @broadshare
    @broadshare 2 года назад

    Been looking for h-tag width issue for long, thanks kevin

  • @jessicashellenhamer8817
    @jessicashellenhamer8817 2 года назад

    Kevin... are you a psychic by chance? I just completed the NFT challenge on Frontend Mentor and the heading was bugging me because the hover effect would activate even when I wasn't hovering directly on it... I wasn't looking to fix it, to be honest. Was just gonna live with it... out of the blue I see this. Bam. Issue solved. Thank you. You always seem to have exactly what I need when I need it.

  • @batsunet
    @batsunet 2 года назад

    KEVIN, this is exactly what I needed!!!!! Thank you!!!!!

  • @baphometgaming1056
    @baphometgaming1056 2 года назад

    Thank You for your work Kevin! If you ever have time for something like that, i definitely would love to see more projects, big or small, that show how You work, all your mistakes and thought process so we can keep getting better at frontend and see how a project is built in real world.

  • @astrit
    @astrit 2 года назад

    My fav max-content have been using it where possible and I love it.

  • @codercow1941
    @codercow1941 2 года назад

    I knew of min and max-content. Never knew there was a fit-content as well which seems useful thanks 😊

  • @CoreDreamStudios
    @CoreDreamStudios 2 года назад +1

    Thanks!

  • @draganpetrovic36
    @draganpetrovic36 Год назад

    The best explanation ever found, thanks!!!

  • @JillRhoads
    @JillRhoads 2 года назад

    This video is the holy grail of text widths!

  • @georgesaunders3532
    @georgesaunders3532 2 года назад

    Loving your content Kevin. Gets me pumped to get on the computer and make something

  • @davidlafontant2185
    @davidlafontant2185 2 года назад

    Very useful.Thank you.

  • @shvideo1
    @shvideo1 2 года назад

    Awesome tip and so very well presented. Thank you for sharing your knowledge. Great job Kevin.

  • @komal6816
    @komal6816 2 года назад

    Thanks kevin!

  • @MrBaykalcelik
    @MrBaykalcelik 2 года назад

    As usual it is perfect

  • @reflectionethio9662
    @reflectionethio9662 2 года назад +1

    Thank you keiv I didn't understand them well, Now I do 😊

  • @Sandles888
    @Sandles888 11 месяцев назад

    Kevin your the best been learning from you for years now and purchased classes from you and will do more give me a deal!

  • @kavin.c7448
    @kavin.c7448 10 месяцев назад

    Nice video its really helps me lot.

  • @CuteSkyler
    @CuteSkyler 2 года назад

    This really _widened_ my css knowledge :)

  • @fai6702
    @fai6702 2 года назад

    fit-content is AWESOME!!!

  • @wingmann3632
    @wingmann3632 10 месяцев назад

    You are awsome, thank you very much!!

  • @thomaswiley666
    @thomaswiley666 2 года назад

    I found this information fitting.

  • @matthewstoneking6835
    @matthewstoneking6835 Год назад

    Kevin - You explain everything so well!! Thank you. Hopefully, I will have money one day to buy a shirt and send money. Thank you once again.

  • @ikamy
    @ikamy 2 года назад

    max-content has workaround with display: inline-block and whitespace: nowrap, but min-content is INTERESTING!

  • @GL455_
    @GL455_ 2 года назад

    Thank you :)

  • @kunek079us
    @kunek079us 2 года назад

    maybe a viodeo about animations? I know that you'll explain it in the best way possible :D great channel!!! keep the work goin!

  • @Ana_Alien
    @Ana_Alien 2 года назад +3

    I've heard you often say, "My students do this, etc.." Do you mean your students in scrumba or something else? Because I want to be one of them

    • @RobertMcGovernTarasis
      @RobertMcGovernTarasis 2 года назад +1

      Scrimba, and a couple of his bits there are free, plus also his conquering responsive layout course is free,

    • @KevinPowell
      @KevinPowell  2 года назад +1

      I used to teach at at a school for ~5 years

  • @basantijena9033
    @basantijena9033 2 года назад

    Yep I love max, min .. got to know about fit today

  • @alimantado373
    @alimantado373 2 года назад

    CSS guru!

  • @teveoenlaweb
    @teveoenlaweb 2 года назад

    Woooooow 🔥🔥

  • @kiravolvo
    @kiravolvo 4 месяца назад +1

    hi kevin. i always get confused with this optimal value in clamp what is this 5vw+1rem, cam you explain that one pleeeeeeeease. thank you

  • @BigBadTubaDudeCRA
    @BigBadTubaDudeCRA 2 года назад

    Love the shirt!

  • @OneLifeToShare
    @OneLifeToShare 2 года назад +2

    Hi Kevin, you did 5vw + 1 rem while setting clamp values. I am wondering how you decided that 5vw + 1 rem should be good enough. Is there any video of yours that you can point me to learn to estimate this calculation? Thanks in advance :)

    • @ThetaSimulator
      @ThetaSimulator 2 года назад

      lol turns out Kevin has already done this :
      ruclips.net/video/U9VF-4euyRo/видео.html

  • @mh_kohansal
    @mh_kohansal Год назад

    Thank's Alot

  • @farrukhahmad1430
    @farrukhahmad1430 2 года назад

    Live your videos ❤️

  • @tonimaunde
    @tonimaunde 2 года назад

    fit-content is godsend tbh.

  • @yanaraldaghestani6305
    @yanaraldaghestani6305 2 года назад

    amazing

  • @TheYoucefHam
    @TheYoucefHam 2 года назад

    Hi, I love your tutorial, I learn a lot from them, but I really love to see you make a css modification to existing website and how to deal with it. Thanks 👍.

  • @faysalzoabi
    @faysalzoabi 2 года назад +1

    Thank you very much for the helpful and meaningful contents

  • @patricknelson
    @patricknelson 2 года назад +1

    The “fit-content” value is basically a simpler version of: min(max-content, 100%)

  • @mirjalolochilov8428
    @mirjalolochilov8428 2 года назад +1

    Good video

  • @sivavijay1208
    @sivavijay1208 2 года назад +1

    What is that clamp()? Please gimme the link for the video because I am too lazy to find it 😂

  • @rushi1306
    @rushi1306 2 года назад

    How are you multiline commenting in vscode? DFTBA and again great video!

    • @KevinPowell
      @KevinPowell  2 года назад +1

      You can place your cursor in multiple places with alt + clicking

  • @ThetaSimulator
    @ThetaSimulator 2 года назад

    When using clamp, why is your middle value a vw + rem as opposed to just a vw?

    • @ThetaSimulator
      @ThetaSimulator 2 года назад

      lol turns out Kevin has already done this :
      ruclips.net/video/U9VF-4euyRo/видео.html
      THANK YOU!

  • @impactclub
    @impactclub 2 года назад

    have you tried the clap() with min- max- fit-content as its params?

  • @zackwest75
    @zackwest75 Год назад

    When i tried this on an element, it worked but the element was pushed to the left of the screen when it was in the center how i wanted it. A little help would be much appreciated, please.

  • @RobertMcGovernTarasis
    @RobertMcGovernTarasis 2 года назад

    Love your videos Kevin, but afterwards I desperately wish they where also transcribed / a condensed blog article for quick reference when I’m at my laptop. (If your curious what I mean, see Hacking With Swift Plus, articles are available as video and then transcribed as a blog with code / images)

    • @KevinPowell
      @KevinPowell  2 года назад

      I'm going to be making an effort to turn more of my video content into written content this year! It's in the plans... Just have to get a free things in place first 🙂

    • @RobertMcGovernTarasis
      @RobertMcGovernTarasis 2 года назад

      @@KevinPowell yay! honestly if I can help in some way I’d love to.

  • @alexdionisio9360
    @alexdionisio9360 10 месяцев назад

    👍

  • @FernandoRigoo
    @FernandoRigoo 2 года назад

    How can I learn more about responsive font without using media query? How did you do in the video?

  • @maxmeza4350
    @maxmeza4350 2 года назад

    Oh, magic with CSS

  • @joshhwb
    @joshhwb 2 года назад

    Would there be many use cases you'd reach for max-content over fit-content then? Seems like it covers a lot more!

  • @shubhamtiwary2524
    @shubhamtiwary2524 2 года назад +1

    Do you have a video on clamp. This was the first time I saw it being used and it looked great.

  • @lapridagaspar
    @lapridagaspar 2 года назад

    Great explanation Kevin. I would like to know how to have a background on that title that only goes as far as each line's content... So that when ir wraps the background of "our" doesnt go all the way to "projects"

    • @QwDragon
      @QwDragon 2 года назад

      Wrap contents into span and add background on it. But making a rectangular background is impossible, unfortunately...

  • @TheBaltyboys
    @TheBaltyboys 2 года назад

    So max-content is like changing the display property to inline-block ?

  • @novanoskillz4151
    @novanoskillz4151 2 года назад

    Sir Kevin, can you please do a video where you explain how you determine the necessary values when using clamp. in your example this video you typed in 2rem, 5vw,+1rem, 5rem.... How did you know to use those values?? I've tried clamp and can never get it to work.

    • @KevinPowell
      @KevinPowell  2 года назад

      Keep trying numbers until it works? 🤣🤣
      Utopia.fyi has a nice font-scale generator that uses clamp() as well.

  • @claudiocavalierifoschini5954
    @claudiocavalierifoschini5954 2 года назад

    Great video as always! You used the clamp function for the font-size based on the vw; is there a similar solution to make the font-size responsive using the parent's size instead of the viewport?

    • @KevinPowell
      @KevinPowell  2 года назад +2

      Not yet, but it's in the works!
      In the meantime there is typetura (I have a video on that coming out in a week or 2)

    • @warrenarnold
      @warrenarnold 2 года назад

      @@KevinPowell ok got you on bell, looking forward to that soon. Thanks for your great content as always

  • @legostud
    @legostud 2 года назад

    How is fit-content different from display inline-block?

  • @anokhsinghgill4068
    @anokhsinghgill4068 2 года назад

    Hiii I tried the aspect ratio for image tag but it doesn’t work in safari .

  • @ganeshtoraskar8099
    @ganeshtoraskar8099 2 года назад

    Can you please make a video on Houdini

  • @mangadi3859
    @mangadi3859 2 года назад +1

    Hmmm, what happen if you set the width to max-content, and set the max-width to 100% ?

    • @insanitybe
      @insanitybe 2 года назад

      Was looking for this comment :) probably would work perfectly as expected

  • @jugibur2117
    @jugibur2117 2 года назад

    I'm surprised there isn't a quick way to set a background per word yet. It looks rather unflattering when the background is always aligned to the longest word and surrounds all other, shorter words.

  • @DivididedbyInfinite
    @DivididedbyInfinite 2 года назад

    i had no idea clamp existed

  • @progressisbeautiful1541
    @progressisbeautiful1541 2 года назад

    I had problems with browser supoort on max-content. Make sure you add supoort for all engines.
    Is the fit content depreciated? I think it works on Chrome, but we get an warning on Firefox.

  • @meganweber5057
    @meganweber5057 2 года назад

    Is there any way to make it shrink to the longest line each time it wraps?

  • @yohananmiteo6574
    @yohananmiteo6574 2 года назад

    Thanks a lot for this!! But what abour clam() ;)

  • @JonathanCampDesigner
    @JonathanCampDesigner 2 года назад

    Ok Kevin perhaps a topic for a 'short' - who knows but... I keep getting an issue with the top bar + menu area when displaying a full screen image that has "min-height: 100vh;" - so how do we display the image full screen taking into account the very top bar (normally tel, social icons, etc.) Plus menu and logo? Tried everything. Perhaps the answer is dead simple - PLEASE??? 🤔 I ALWAYS get the image going down more than the screen height...
    🙋‍♂

    • @KevinPowell
      @KevinPowell  2 года назад +1

      The best way is probably too use JS to get the height of those other elements, then use a calc() and subtract that value from 100vh. Sounds more complicated written here than or actually is 😅

    • @JonathanCampDesigner
      @JonathanCampDesigner 2 года назад

      @@KevinPowell Can you point to any good examples (that are simple...) ?

  • @oliver139
    @oliver139 2 года назад

    For max-content, I think a inline-block will be better?

  • @user-ms8ei9le7x
    @user-ms8ei9le7x 2 года назад

    #Kevin

  • @mrlten2907
    @mrlten2907 2 года назад +1

    Wouldn't setting display:inline achieve the same thing as fit-content, at least for a heading or paragraph?

    • @Killyspudful
      @Killyspudful 2 года назад +1

      Not without all of the other side-effects of losing 'display:block'.

    • @KevinPowell
      @KevinPowell  2 года назад +2

      As Killyspudful said, that has other side effects as well, like no margin top and bottom, padding potentially overlapping items, and if you have more than one, one after each other, then they'd go next to one another

  • @8koi139
    @8koi139 2 года назад

    I use fit-content almost every day lol

  • @injSrc
    @injSrc 2 года назад

    max-width: min(max-content, auto)

  • @lvekua
    @lvekua 2 года назад

    Can css function clamp() use the min-content, max-content, fit-content?

    • @KevinPowell
      @KevinPowell  2 года назад

      Good question, but I don't think so. Pretty sure it needs fixed values, but I could be wrong. Worth testing out!

  • @QwDragon
    @QwDragon 2 года назад

    The main problem with it that when fit-content wraps text, it behaves the same way as auto does. It would be very cool if it could've shink after wrap, but seems like it's impossible in css :(

    • @KevinPowell
      @KevinPowell  2 года назад

      Yup, that's just not how it works, since everything is a box 😕. Though that did make me think of something that *might* work, but I'm on mobile so I can't test it right now. If it does, I'll make a video on it 👍

    • @delulu6969
      @delulu6969 2 года назад

      You wrap the text in a span (I'm not sure if setting display:inline on heading will work) and then use box-decoration-break:clone

  • @FredUA
    @FredUA 2 года назад

    What about cross-browser compatibility?

    • @KevinPowell
      @KevinPowell  2 года назад

      All of them works on all modern browsers

  • @wov2004
    @wov2004 2 года назад

    @media ....?

  • @quentin443
    @quentin443 2 года назад

    Why fit-content is not a default behaviour ? Auto width isn't really intuitive...

    • @KevinPowell
      @KevinPowell  2 года назад

      Auto with is much more useful for layouts though!

  • @AlibekKulseitov
    @AlibekKulseitov 2 года назад +1

    max,min, fit content are useless. Just use display: inline-block, you dont need any things to do

  • @mrCetus
    @mrCetus 2 года назад

    I found the tutorial interesting, but right in the end you showed the clamp function and that was EXACTLY what I was looking for on my personal website, but didn't know existed. Thanks Kevin! You're awesome! As a Data Engineer/Backend Python Developer, I always learn new things with your videos.