Simple solutions to responsive typography

Поделиться
HTML-код
  • Опубликовано: 28 июл 2024
  • In this one, I look at two simple ways to make maintaining your site's typography much simpler!
    🔗 Links
    ✅ The codepen: codepen.io/kevinpowell/pen/MW...
    ✅ More videos on responsive layouts: • Responsive Layouts
    ✅ My free course on responsive layouts: courses.kevinpowell.co/conque...
    ⌚ Timestamps
    00:00 - Introduction
    00:49 - The problem most people run into
    02:28 - Using custom properties
    05:16 - The issue with viewport units
    07:18 - Using clamp()
    #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 RUclips 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!

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

  • @technikhil314
    @technikhil314 2 года назад +66

    That +1rem is noiceeee I love it. Pinch zoom is issue with viewport units.

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

      this

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

      Yup, now off to add this to every clamp() I've written.

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

      Can someone further explain this? I don’t understand. Thanks

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

      @@bulkywallnut5674 as you zoom in your viewport shrinks hence actual vale of vh and vw also goes down but rem stays same regardless of viewport size.

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

      Never considered pinch zoom 🤔
      Otoh, why would you want to pinch zoom if font size is appropriate?

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

    “frontend friends.” for months i thought he was saying “friend and friends.”

    • @iamkeir
      @iamkeir Месяц назад

      Mind = blown 😮

  • @MilanRegec
    @MilanRegec 2 года назад +64

    So glad to see Kevin now includes accessibility concerns in every video he makes. This is so important for the community. Thank you!

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

      @avfr like derek banas? anyway who hurt you?

    • @TuringTested01
      @TuringTested01 2 года назад +4

      @@miyalys a blind guy with hearing issues took his girlfriend and now he's sad

    • @throwbacksfather6625
      @throwbacksfather6625 Год назад +1

      @avfr what the hell is a soydevs

  • @JuanPablodelaTorre
    @JuanPablodelaTorre 2 года назад +10

    I've been using clamp instead of media queries for a while now. But using both with variables is brilliant. I absolutely love it.

  • @gregoryolenovich6440
    @gregoryolenovich6440 2 года назад +5

    Damn your responsive layout tutorials are so helpful and I'm a fairly experienced dev. I love the clamp thing. I have been using min to get something similar but I like clamp even more.

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

    Great, helpful staff. Love how you explain what I shouldn't use. Made my day. Thank you!!

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

    Really good stuff. I'm learning a ton from your videos. Thanks for putting them together.

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

    Man , that's absolute genius, been fighting with this for years! I'm saving this video with my legacy firefox youtube downloader, that vid going in my library!

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

    Kevin, you are my savior! Yet another amazing video ❤️Thank you so so much and I wish you an amazing new year!

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

    Amazing work man, you have taught me a lot of things from your videos! Keep it up!!

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

    As always, great stuff. I think min, max, and clamp are pretty awesome.

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

    The Clamp trick is amazing!!
    Thank you for the tips!

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

    As always, outstanding. Thanks, Kev!

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

    Thanks for this video Kevin. Just used (clamp) for one of my designs after this. Super helpful.

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

    Thank you, Kevin, that was precisely what I was looking for. I have subscribed for more. :)

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

    Awesome as always. You never disappoint!!!

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

    Amazing stuff as always, thanks a lot!

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

    Excellent technique with the clamp + calc (implied)! :) Thanks!

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

    Yet another great video Kevin! Thank you.

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

    Great Video, Right now, was currently using vw, vh approach never heard of that clamp function seems really interesting, the only issue i see is the support. It's actually less supported than grid-layout, but surelly when browsers keep evolving will be a must use.

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

    I've never heard about clamp, I loved it, thanks for the video.

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

    it's nice to see a video with material about which you knew for 6 months already

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

    I love your approach. Great job.

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

    This is fantastic, thanks so much for these fun vids

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

    Wonderful.
    Understandable.
    Incredibly useful.
    Thank you.

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

    Wooooow, you rock!!!
    Your videos are awesome, clear and to the point.

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

    Objective and Useful video! Thank you!

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

    Neat! I've tried to do this with .less and never was able to, this is really nice!!

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

    What a great solution!!! I really enjoyed this vid (whilst eating breakfast ha ha). Thanks Kevin 👍🏻

  • @roberotful
    @roberotful 2 года назад +4

    I've been sacrificing accessibility a bit on some of my projects by using viewport measurements, love the clamp idea. To solve the problem of vw getting super big/super small I had swapped to vh which I actually find to be a pretty good scalable solution - works well on both desktop and mobile once you find the sweet spot - if you don't mind it always being the same size regardless of zoom (which I think you obviously should mind now that I know clamp exists!)

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

    Interesting!
    I tend to use em (not rem) in all instances while making sure to always keep things very simple:
    End-points (so , , tags and the like) get an EM value, all padding, margins, etc. use em values, image sizes use em values (with srcset so the image can be much larger but display properly based on the actual display needs) or vector art.
    Then I will have "containers" like a or , or even a which can be designed to "mod" the size (say you want "big quotes", then that tag gets a font-size of 1.4em for example). Anything drastic or that could have many exceptions will be set using a class instead of a tag so that I don't have to override these em values constantly.
    Then I just use my body's font-size as a responsive breaking point. That clamp trick would work wonders there, since it would affect the entire site's content within controllable bounds!

    • @user-yz5hj3zg2x
      @user-yz5hj3zg2x Год назад

      I don't know if you already watched this, but if not, take a look: ruclips.net/video/pautqDqa54I/видео.html

  • @user-uj2ln8bd2r
    @user-uj2ln8bd2r 4 месяца назад

    Thank you for this video. Really helpful.

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

    exactly what I needed, thank you!

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

    clamp(3.5rem, 12vw + 1rem, 12rem) which is amazing. Now I will be use in my all projects

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

    This is something I've been trying to figure out how to do via SCSS. Any chance you make a follow up with how to do this?
    Keep up the great work.

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

    I am so happy I found this channel 😭

  • @ryandornanuk
    @ryandornanuk 2 месяца назад

    Amazing video, thank you so much.

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

    awesome, exactly what I neeeded

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

    Great video, thanks Kevin

  • @photoinshot1355
    @photoinshot1355 7 месяцев назад

    Great tutorial very helpful and demonstrates responsive text methods very well, thanks. I am not very experienced with css so this is a great introduction to responsive text. I am very interested to learn more about the overall layout design with this newspaper - magazine type layout which is great and makes the whole page more interesting to look at and more inviting to read. Do you have another video explaining the concepts behind this layout design? I can work out quite a lot from the code you kindly supplied in the codepen (thanks!) but some of the code I don’t understand. Thanks again!

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

    Clamp creates an s-curve for mapping font size to screen size. You can also achieve this with calc(#vw -#vw) but setting bounds with clamp() is much more Design Driven. Anything that helps detangle the mental exhaustion of mapping design goals to math is a big win

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

    this video is awesome thanks a lot Kevin

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

    Really good stuff., thank You!

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

    Wow this is great! Thank you thank you thank you!!

  • @benja-min1588
    @benja-min1588 2 года назад

    Thank you Kevin!

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

    Great that you explain we should not base font size on the view port size. It is not how typography works. Typography works on view distance (and you eye sight) so unless our devices get a sensor to measure how far our eyes are away from the screen we are reading, we have to work by the experience we have. Here we are in luck as we already use type for centuries, so we have some experience. An experience that is supported by some science of the last century where reading over distance became a real thing, like how large should type be on a road sign...
    The other great thing I would implement as soon as possible is to gather as much typographic parameters and behavior in one place, somewhere at the beginning of (css) files.

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

    Literally saved my day!!

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

    awesome job dude, thanks.

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

    Defo my favourite RUclips coder ♥️

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

    Wow This is Great Man ❤️

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

    Great! ♥♥♥ :-) Thank you Kevin. Really helpful.

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

    Man, why is this guy so awesome with CSS.

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

    Killer tutorial !

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

    He has video for my every css doubt

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

    Thats awesome🔥🤯

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

    Kevin, you are the fucking best, you know, right?. This week I learned A LOT from you. Your content is incredible. Everything I have to do and find out how to on my projects, I search and you explained it better than anyone.

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

      Also finishing your CRL 21 days course

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

      Thanks so much! So happy that you're enjoying me content 😊

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

    People really gotta clamp down on text like this :D

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

    Thanks Kevin!

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

    Thanks for the pro tips.

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

    Pure gold right here.

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

    Thank you very much.

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

    pure gold

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

    LOVE that t-shirt!

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

    damn that is smart, never thought about root on media queries

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

    Great content as always! :) I really appreciate that you talk about pros and cons for every decision. I have only one question, if I read correctly clamps() is not supported by Internet Explorer... so how the page behaves when you open it in IE? I am not sure how many people still uses the IE but I think it is still in use in business segment.

  • @AFE-GmdG
    @AFE-GmdG 2 года назад

    CSS Variables - a great invention!

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

    I have been using a root vw font-size that is based to the Adobe XD artboard size.
    I'm using scss functions to aid me with this but it can be done with calc.
    this would look something like this:
    html{font-size: calc(20 / 1280 * 100vw)}.
    This will make it so that 1rem is 20px at a viewport width of 1280px.
    As you resize the viewport this relation will stay the same.
    Then you can use a different relation for a mobile width using media queries.
    This allows not just my text but other elements with rem/em values to scale perfectly with the viewport width.
    As a nice bonus I can use the same px values used on the XD artboard. I just have to convert them to em/rem.
    I use scss functions for this again to keep things neat but you can use calc for this as well.
    With a container width of 500px it would look like this:
    width: calc(500 / 20 * 1em);
    20 being the base font-size that is also defined in the root font-size.
    This certainly brings a lot of advantages. My designer has a print background
    so a lot of his layouts heavily rely on the right ratio between text and other
    elements like images.
    But of course there a downsites as well. Aside from running into some unexpected
    bugs from time to time the two major issues are:
    1. zoom accessibility
    2. some layouts don't work very nice on larger screen sizes because you end up with very
    litte content being visible at a time.
    this might all be a bit much for a youtub comment but oh well xD

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

    Wow, that ‘clamp()’ 🤯 i didn’t know about it. Merci

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

    I built a logo name slogan hero in svg and to approve the relations always stay the same gave the svg a relative unit. Works fine for all screen sizes and is super fluid, but is definately no work case for paragraphs 😄

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

    I like your css content

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

    Loved the t-shirt... and tutorial of course...

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

    That is great when you have only one css file, but I use quite a few css files, one for images one for navigation etc, all my media queries are in one css file, easy to find what you are looking for indeed.
    EDIT: all my roots are also within one css file.

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

    waoo this just blew my mind

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

    I think the fall in love with CSS bit has drastically changed!

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

    Those two :roots...yet another "oh, that's smart" moment in your videos. Thanks!
    If I understand correctly, that 1rem of the 12vw + 1rem is just a token amount, so you can pinch the screen -- is that right? If so, is there any reason NOT to put similar measurements throughout your CSS? e.g. for the --fs-400, could you put .5vw + .5rem, or whatever the size equivalent would be?

  • @lemonboy7524
    @lemonboy7524 11 месяцев назад +1

    thank you for help me : )

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

    Kev. can you please do a tutorial on css design system/layout/structure. I will really be looking forward to that. thanks

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

    Awesome 👏

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

    amazing!

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

    thanks!

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

    Something that I don't really understand is:
    Do I have to adjust the font-size for every element?
    Because if I change the font-size of , every rem unit will adjust as well, which I don't want.
    It seems, as if I should define all font-sizes via classes, which I think is unnecessary for all regular text. I just want to overwrite the font-sizes at each breakpoint, like I do with h1-h6 and so on.

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

    Woah, clamp() is native CSS? Awesome!

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

      I think scss is moving to native css.

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

    Clamp is a good one. Thanks. I kinda wish they had something where you could set a size based on the parent container's width instead of the whole viewport.

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

      percent!

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

      @@roberotful I 100% agree with what Rob said 😉 Or is it 80%? I don't know anymore.

    • @ormuriauga
      @ormuriauga 8 месяцев назад

      Doesn't work for font-sizes though :(@@roberotful

    • @roberotful
      @roberotful 8 месяцев назад

      @@ormuriauga I think setting font-size as percentage goes by percentage of the element-level font size, similar to em (I could be totally wrong, just my present understanding). I think percentage is a bit unintuitive for font sizes though, I usually use rem!

  • @Peter-yd2ok
    @Peter-yd2ok 2 года назад

    Thanks

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

    This is a great approach thanks Kevin, the vars, I have been struggling to get my clamps just so with this last project I am working on and am thinking I will drop it for the custom variables approach for future projects and give the IE browser a fallback. One thing I'd like to add, the mobile body text needs to be 1.3 times bigger than desktop because people tend to hold the mobile screen further from their face.

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

    Thanks!

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

    Another sub for you ❤✌

  • @TK-lv9sc
    @TK-lv9sc 2 года назад +2

    I have another method that works quite well for me.
    First, on root, I add a base font size with viewport width units, and then media queries that change that base font size. For example, for large screens "font-size: 1vw", but for smartphones "font-size: 3.5vw".
    Then I set everything using clamp usually, just to make sure that everything is in line and doesn't get oversized. Example "font-size: clamp(16px, 1rem, 22px);"
    It works great for me, and everything scales almost fluidly when resizing the window. I also use this root font size for margins and padding as well in some cases.

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

      What clamp generator tool do you use?

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

    Ok, honestly I rarely ever say that but today I actually learned something I didn't know about..,

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

    KEVIN SIR LOVE FROM INDIA ♥️🤘
    KEEP UP THE GUD WORK 🙏🙇

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

    thanks

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

    Genious!

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

    Je n'ai jamais réussi à trouver facilement les équivalences entre les viewport width and rem units.. Super astuces en tout cas..

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

    Great solution. And by the way you have exactly 350.000 followers by now.

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

    All fonts - make in Rem < and @media maybe change just a ----- Rem?

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

    How to place different length text into the div with fixed width and height?

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

    Seems like your clamp scaling will behave differently depending on the zoom level. The lower & upper limits grow faster than the target (because zoom only affects rem not vw), so I would expect >100% zoom to min-out/max-out at a proportionally wider screens, and

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

    dude the vw is a miracle

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

    Thanks Jon Stewart !

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

    whats with 499 and 599 and 699. almost every time you have you remove 99 to replace it with 00?