The problems with viewport units

Поділитися
Вставка
  • Опубліковано 15 чер 2024
  • Conquering Responsive Layouts (free course): courses.kevinpowell.co/conque...
    Join the Discord: kevinpowell.co/discord
    Viewport units often feel like this cheat code that makes things so much easier when you first discover them, but they actually are problematic for a number of reasons, from creating horizontal scrolling to accessibility issues and more, so in this video I look at the problems that people run into by using them and offer up some alternatives.
    🔗 Links
    ✅ Discord: kevinpowell.co/discord
    ✅ Dynamic viewport unit browser support: caniuse.com/mdn-css_types_len...
    ✅ Codepen: codepen.io/kevinpowell/pen/Po...
    ✅ Conquering Responsive Layouts: courses.kevinpowell.co/conque...
    ⌚ Timestamps
    00:00 - Introduction
    00:22 - Issue 1: Using 100vw
    02:00 - Issue 2: The problem with 100vh
    07:28 - Issue 3: Fluid layouts
    #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 UA-cam 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!

КОМЕНТАРІ • 410

  • @Brunoenribeiro
    @Brunoenribeiro Рік тому +150

    Liking the new format, Kevin! No logo splash, faster intro, going straight to the juicy content. Hope it doesn't hurt your channel's metrics! Thank you for giving it a go ❤️

    • @bobwilkinsonguitar6142
      @bobwilkinsonguitar6142 7 місяців тому +6

      Devs watch UA-cam on 2x speed, angrily scrolling until they find the code that fixes their bug, I'm /sure/ this is helping😂

  • @jasonoconner7863
    @jasonoconner7863 Рік тому +55

    Wow, I was just the other night ranting about the vw units causing horizontal scroll and ChatGPT being unable to help me. Thank you!

    • @NotJayG
      @NotJayG Рік тому +5

      you can use overflow-x: hidden; or width: 100%; instead

  • @developerpranav
    @developerpranav Рік тому +41

    100vh has been problematic for me! never had to use 100vw, but it's good to see that dvh and svh are getting support! Thanks for covering this! :D

  • @FeresVocalArts
    @FeresVocalArts Рік тому +8

    Man, these were the most productive 13 minutes I've been into since so long!
    Thank you so much!

  • @timseguine2
    @timseguine2 Рік тому +53

    I used to do full-stack dev but quit back when IE7 support was still a thing that people sometimes had to do. I enjoy how much better things have gotten with decent html5 and css features, but my "oldschool" brain sometimes has trouble with the stuff we could never really use like this. It is great to have videos like this that distill the quirks down into manageable chunks without hours of experimentation.

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

      Same!!

    • @ongke3655
      @ongke3655 Рік тому +2

      IE should be excluded from the world. Even IE10 or 11

    • @timseguine2
      @timseguine2 Рік тому +2

      @@ongke3655 support these days is completely unnecessary. But this was coming from back in the day when it still had 10%-20% market share. Not supporting that was basically just bad business back then.

  • @yarrrno
    @yarrrno Рік тому +1

    This exact header 100vh issue on mobile. arghhhh. I think i asked about it like 6 months back on your discord channel. There was so little info on web about the new units. Was super happy to see this video. Now its way more clear how to make use of the new units. Truely appreciate your work, thanks in behalf of the whole world :D

  • @grymmjack
    @grymmjack Рік тому +1

    Thanks for the video. Subbed. I used to do a lot of web design, but haven't in ages. While things have definitely improved since those days, it's a little crazy to see the struggles with the same old problems on new tech. Will use your channel to get back up to speed. Appreciate your approach/method/sharing/pace/explanation/allthethings.

  • @VivekTR
    @VivekTR Рік тому +4

    I've faced many of these problems. A lot has been clarified in this video. Thank you, Kevin!

  • @potrosanjuan
    @potrosanjuan Рік тому +5

    I didn't know why that annoying horizontal scroll appeared, I don't know what I'd do without your videos, thank you Kevin!!!!

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

    This is the first video I watch from your channel and I can say, with absolutely no doubt, that I just became your fan, man! Thanks!

  • @fiddle_n
    @fiddle_n Рік тому +19

    I've started web dev this year (through the Odin Project, which is how I found your channel incidentally!) and Issue 2 was the bane of my life last week. What's worse is that most Google results don't include svh at all - I had to *really* look to find it. But wow is it a great unit to use.

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

    This is awesome. Good job Kevin. I'm very grateful for all of your excellent content!

  • @fernlovebond
    @fernlovebond Рік тому +1

    Damn! You always teach me fascinating things, and make me want to tinker and play. Thank you for giving such clear ideas about how the various rules work. You're so awesome at this.

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

    Couldn't fall back to sleep so I've been flipping back and forth between you and Web Dev Simplified. You guys make great videos. I'll definitely have to come back to this one when I'm working on my projects.

  • @boheeatelier6681
    @boheeatelier6681 5 місяців тому

    Great! I have just enrolled for the free course. I learn so much from your videos and I just love playing with CSS, so fun!

  • @christian-schubert
    @christian-schubert Рік тому +69

    Now, haven't been excited about a CSS topic probably since CSS grid came up - since when have 'svh' units been a thing?! (Also, how could I ever miss this?!)
    This LITERALLY IS a gamechanger - developing for those collapsing addressbars has always been SUCH a nuisance - thanks Kevin! 👍

    • @KevinPowell
      @KevinPowell  Рік тому +22

      They're relatively new, so do keep an eye on browser support, though it is pretty decent!

    • @qzbnyv
      @qzbnyv Рік тому +1

      Thank you UA-cam algorithm for bringing me to this amazingly useful channel 👏👏
      And thanks Kevin 👏

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

      oops though that was a top-level comment. oh well

    • @thedigitalceo
      @thedigitalceo Рік тому +1

      It’s so sad that there’s still no real solution for 100vh on mobile. svh also doesn’t seem supported by iPhone Safari which is what our clients complain about the most.

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

      @@thedigitalceo It works on 15.4 onwards according to CanIUse, so you could set it to 100svh and then also declare 100vh as a fallback if it isn't supported by the browser (with a padding hack as well)

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

    Love the video 👍 A good summary of the issues and solutions that everyone should be aware of

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

    Hey Kevin! Nice shirt 😁🤘 just wanted to say thanks for the clearness of your videos, always find myself learning new things every time.

  • @ClashRoyale-pt9zj
    @ClashRoyale-pt9zj Рік тому +1

    wow, i've never known anything about that "svh" unity, it's an incredible solution for a lot of projects that could have problems like the showed on the video, thx kevin!

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

    Straight to the point and well presented - perfect 👌

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

    I JUST WANNA SAY... I LOVE YOU......... IVE BEEN SEEKING FOR THE SOLUTION OF THIS PROBLEM FOR A LONG TIME WHEN I SAW YOUR VIDEO AND BAMM!!! SOLVED!!! THANK YOU!!!!!

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

    I thought this was a contradictory post from one of your contents, glad to learn this was kind of a continuation about dynamic viewports. I stopped using viewports and started using dynamic viewports because of your videos.

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

    Exactly what I needed! Thanks for this video, it’s the best

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

    Wow 2 days back i was searching for this !!! 😂❤️ Great one

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

    Kevin, you are a golden find

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

    Perfect timing for this, thank you, as always

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

    Man this was extremely informative. I definitely have used view port values a lot in the past..

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

    @kevinpowell although the footer is not sticky "stays at the bottom" I use flex: 0 auto in the first div bellow the body, then once the content inside goes beyond the height it can initially display the footer will be at the bottom of the content. to me it's not good design to keep a footer in view, as it's taking up space all the time. Always appreciate your work Kevin.

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

    Hi kevin , its really amazing that I have a problem in my code and in the NEXT DAY you make a video about my problem, happened already like 7 times

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

    Once again bringing accessibility issues. Thank you so much for this.
    Respect + 🤟🏻

  • @JPNK13
    @JPNK13 Рік тому +21

    Are you using something like Nvidia's Eye Contact feature? Around 1:40 your eyes suddenly change and it stood out to me.
    I appreciate the content either way! Thanks for uploading.

    • @vokhactri
      @vokhactri Рік тому +2

      i also spot that weirdness

    • @trubnikov
      @trubnikov Рік тому +1

      That was scary as shit!

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

    Thank you! Love your professionalism

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

    I don't use vw for everything but sometimes I see people doing so. Now I'll give these people the link to this video :) Thanks Kevin!

  • @frankroos1167
    @frankroos1167 Рік тому +2

    So far I have only used viewport units on pages that fill the viewport exactly on regular screens, either landscape or portrait. For that use-case it works pretty well. For other use-cases I have never considered them, not because of the problems it may cause, but because the alternatives I did use came more natural.
    min/max/clamp are so good. And combining them with container-query-units is awesome.

    • @nevyanplamenov5409
      @nevyanplamenov5409 Рік тому +1

      Thank you for sharing about container query units, i study responsive design right now and i had no idea those even existed...

  • @g-pg
    @g-pg Рік тому +2

    Earlier today I was wondering how to fix a problem with an element not showing properly on mobile because of the 100vh differences between devices. Thank you very much Kevin!

  • @dandejy6520
    @dandejy6520 8 місяців тому

    Your videos are always very helpful. 👍

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

    I was wrestling with this the other days, so happy to hear this because now it makes sense.

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

    Great video. I'm investigating CSS functions now. Thanks.

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

    Very good video ! Thanks for your always great work

  • @ankurpathak108
    @ankurpathak108 Рік тому +16

    Hey Kevin , thanks for the detailed information about View ports 😊
    By the way can please explain the clamp() function in detail in a video ?

    • @KevinPowell
      @KevinPowell  Рік тому +15

      Already have one :D - ua-cam.com/video/U9VF-4euyRo/v-deo.html

    • @dariokartal9453
      @dariokartal9453 Рік тому +1

      What clamp() does, I used to do with calc() combined with css variables for min and max.

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

    omg thank you so much, I have the problem with 100vh height in my project and the svh is probably gonna fix it!! Thank you!

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

    Very helpful tips especially with 100vw. One of the points I tackle through with every project...

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

    Absolutely game changing!

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

    I build with a mix of units and than run a PX to REM convertor before running final checks on my responsiveness. I've found that's working for me as I get more involved with Accessibility and working with multiple developers.

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

    You are number 1 and my best teacher!
    👍

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

    Thank you sir for the SVH value trick 👌🏻😊

  • @VasilyPavlik
    @VasilyPavlik Рік тому +1

    Thanks a lot! As usual I found your video awesome. (Gone to remove all 100vh from style.css files) :)

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

    Super helpful. Great channel!

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

    omg thank you so much for the "100svh" tip. In my case it's a sidebar which must have the exact same height as the viewport but on tablets it was having that same issue.

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

    thanks Kevin for another great video. Good to know you're telling people about your courses here too now. More people should learn from you, I feel like there's no one better in this field than you

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

    Thanks to Kevin, now everything I say or do has 'awesome' in it.

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

    This was amazing to learn about, I've just been using the h-full (100%) trick, will try out the svh way! Thanks

  • @fredbcruz
    @fredbcruz 7 місяців тому

    Pretty on point. I liked this style

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

    Great video as always! QQ - do you use any software for eye contact? There are some weird artifacts in the video ~1:36 and ~1:42 where your pupils shift noticeably.

  • @muhamadsarhad6566
    @muhamadsarhad6566 9 місяців тому

    wonderful video as always

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

    Oh wow, you only just uploaded. Great video!

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

    Awesome video. Thank you.

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

    Great tutorial man keep it up!!! Some time ago you made a tutorial about using 100vw inside a container which its width was like 960px or something, but the 100vw was not affected by the container. Can you please share that video? Thanks

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

    Hella good video. Subscribed.

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

    Excellent. I always want to know some solution to this problems

  • @mike5904
    @mike5904 Рік тому +1

    Hi Kevin, You now have around 600k more subscribers since writing the sign up page for the course 👍. Thanks for the relatable, real world content.

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

    Thx for another usefull info :)

  • @skyvibe1818
    @skyvibe1818 Рік тому +11

    Oh using AI eye tracking are we? 😆
    Great content as always!

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

    I can see the NVIDIA Broadcast! Amazing content by the way. I do web design on the side and you have helped me so much! Thanks alot

    • @kdmadej
      @kdmadej Рік тому +2

      For a moment I thought I was going crazy 😅

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

    Thanks man! dvh saved my life

  • @brandonwhite5139
    @brandonwhite5139 6 місяців тому

    Hello Professor KP! 😇 I am studying UX Design. Longtime artist trying to figure out front-end development. I liked your videos right away as soon as I noticed have you kept your profile in a circle frame. Plus you kept looking back towards the camera. You must be a writer. Funny thing. I watched/listened to a couple of your videos on 1.5 and 2 playback speed.

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

    That 100vh part was very useful because I want the comment section on videos on my site to be off screen until scrolled so the comments don’t need to be loaded unless a user scrolls to see them

  • @James-zr1lu
    @James-zr1lu Рік тому

    Nice mate, keep it up.

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

    This is useful. Thanks.

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

    THANKS. I think I just found a great problem in my project

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

    Great 👍 Thank you!

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

    Loved it !

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

    Thanks so much for this. I was wondering why my sidebar with 100vh was being cut off on mobile browsers

  • @electronicmusicartcollective
    @electronicmusicartcollective 6 місяців тому

    MY CSS GURU!!! THANK YOU!

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

    Loving the Nathan Barry shirt! 👕

  • @jcstelt
    @jcstelt Рік тому +1

    Hi Kevin, why do you declare a vw + rem als your default size in clamp? Why not just declare a somewhat larger vw? What’s the difference?
    Love your channel by the way!

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

    1:41 there is an eye glitch on Kevin face. Pretty interesting times we live in :)

  • @natarajanraju4198
    @natarajanraju4198 6 місяців тому

    Love your content

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

    Thank you my dear sir

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

    Thanks, I didn't know about dvh or svh. It's scary that Google/UA-cam knew I needed to see this video...

  • @Akimb321
    @Akimb321 Рік тому +43

    Regarding the 100vw producing scrollbar - I think it's not because the vw does not take into the account the scrollbar, but because (in case of body) there is already some margin applied on it. The scrollbar disappears when the margin is removed

    • @nervousstate
      @nervousstate Рік тому +2

      This exactly too.

    • @calyodelphi124
      @calyodelphi124 Рік тому +1

      Yeah, this. Exactly this. When sizing elements, the default behavior is to apply the sizing only to the content area, which only includes the content itself and ignores padding, borders, and margins. You can include the padding and borders in your element sizing by declaring "box-sizing: border-box;" but then that still leaves the margins left over. You have to also set "margin: 0;" and then things should work.

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

      You're right, i used to follow and i got better results.

    • @andrefig822
      @andrefig822 9 місяців тому

      This is only true for mobile browser/devices. Desktop 100vw DOES produce a scrollbar as of 2023. Chrome is in the works to provide a solution for that, it had a custom flag to enable overlay scrollbar until a few time ago. There's one hacky solution though: "width: calc(100vw - (100vw - 100%))", but I can see a case where you would want a 100vw instead of 100% through parent-child elements.

  • @code.cracking
    @code.cracking Рік тому

    Thank you very much

  • @rproctor83
    @rproctor83 7 місяців тому +1

    I always set my body elements to flexbox column with a min-height: 100vh, then align my footer to the bottom with the content area set as flex grow. Seems to work well.

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

    needed this

  • @Its-Just-Zip
    @Its-Just-Zip Рік тому

    I'm glad I started playing around with HTML and whatnot after svh became a thing in the standards... Learned using them from day one. And I probably use them too much

  • @boomshakalaka656
    @boomshakalaka656 Рік тому +1

    to fix to zooming in and out problem you can use this :
    html {

    font-size: clamp(0.75px, 0.05vw, 1px);

    }
    now if style all you elements using rem in of px i.e( 100rem instead of 100px ) you get the benefits of a fluid layout resizing and the ability for your users to resize their content.

    • @joshwf
      @joshwf 9 місяців тому +1

      THANK YOU

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

    Great video. Could you point me in the direction of doing a Trello or Jira style column scroll without using vh? I've struggled with and without I guess.

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

    Awesome stuff Kevin but there is always but :D
    I spend a lot of time to adjust my webiste to work on all types of mobiles and to be honest even nowadays there is a lot of mobile devices with old chrome running on it.
    Imagine this situation that the button is on the bottom on the page, then even when you set height as 100vh as fallback the button will be hidden under bottom bar. One thing that I am missing here is fill-available unit. This help sometimes.

    • @KevinPowell
      @KevinPowell  Рік тому +2

      You could do a hight: 95vh; or 90vh for the fallback 🙂

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

    Happy birthday belinda!!

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

    I like those analytics vidéos !

  • @zoirjonabduvohidov2897
    @zoirjonabduvohidov2897 4 місяці тому

    very very usefull info nj

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

    Excellent 😊

  • @jeankhouri
    @jeankhouri Рік тому +1

    Are you using something to fix eye contact on your videos or are you AI? Great video!

  • @ShaunLevett
    @ShaunLevett Рік тому +1

    I do use a utility class to make panels restricted to a container look like they are full viewport width (width: 100vw; margin-left: calc(50% - 50vw).
    I got it from an Andy Bell tutorial. I've not seen any horizontal scroll issues though. Could just put overflow-x: hidden on parent of course. Will have to chck this, but there's no other way to do this one really.

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

    UA-cam recommend me this today. And I can't stop my finger to subscribe him.

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

    svh! What a life saver ❤️

  • @KaaptnIglo
    @KaaptnIglo Рік тому +1

    didn't svh / dvh. Cool tip, thanks

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

    Times before s/dvh's something like calc(100vh - 16px) or just random numbers in parts with 100%.
    Font-size's in vw, remember that also before clamp.
    Both have been bad roughly since post IE8.

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

    Great video. Do you have an entire video on clamp and min? That would be great. Thanks!

    • @KevinPowell
      @KevinPowell  Рік тому +1

      I do! ua-cam.com/video/U9VF-4euyRo/v-deo.html

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

      @@KevinPowell It was indeed a very informative video, thanks! :)

  • @serychristianrenaud
    @serychristianrenaud Рік тому +2

    Thank 👍