Use these instead of vh

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2023
  • Looking to step up your CSS game? 👉 kevinpowell.co/courses?... I have a bunch of courses, including several free ones.
    I see people use `vh` a lot, and then complain that it doesn’t work the way they thought it would, so in this one, I explore a few other options that we have, which are `dvh`, `svh`, and `lvh`. Along with these, you could also use `dvb`, `svb`, and `lvb`, which are the logical property version of the height units, but for the block-size.
    🔗 Links
    ✅ The example page: viewport-unit-test.netlify.app/
    ✅ The GitHub repo: github.com/kevin-powell/viewp...
    ✅ Up to date browser support: caniuse.com/mdn-css_types_len...
    #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 TH-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!

ความคิดเห็น • 341

  • @fersahahmet9597
    @fersahahmet9597 6 หลายเดือนก่อน +395

    You are King of CSS not necessarily because you know everything but a very deep understanding of what you are talking about which i personally love and admire the most about you. Thank you Kevin for every single effort of you

    • @BGdev305
      @BGdev305 3 หลายเดือนก่อน

      ditto!

  • @Dexter101x
    @Dexter101x 6 หลายเดือนก่อน +441

    Just when I got to use the vh properly, lol

    • @Rhidayah
      @Rhidayah 6 หลายเดือนก่อน +31

      Me with big brain using 100%

    • @elpioterro
      @elpioterro 6 หลายเดือนก่อน +5

      I have the same situation haha

    • @kikevanegazz325
      @kikevanegazz325 6 หลายเดือนก่อน

      The guy is a developer - streamer, not the CSS god who is commanding you something. If 100vh that’s working for you and you do it right, keep it up.

    • @yay8507
      @yay8507 6 หลายเดือนก่อน +5

      Well its the same thing anyways

    • @marvellousgboun6068
      @marvellousgboun6068 4 หลายเดือนก่อน

      😂

  • @arjunjayakumar4841
    @arjunjayakumar4841 6 หลายเดือนก่อน +155

    The timing. I was fixing a layout and was experimenting with dvh. Will surely try out svh as well. Thanks Kevin

    • @ryrilya2289
      @ryrilya2289 6 หลายเดือนก่อน +1

      Same here 😅

    • @bellion23
      @bellion23 6 หลายเดือนก่อน

      How did it go?

    • @CantIllaoiThat
      @CantIllaoiThat 27 วันที่ผ่านมา

      How did it go?

    • @mujahidarshad
      @mujahidarshad 5 วันที่ผ่านมา

      bro can you tell me difference between vh, Lvh, svh and dvh.coz i am not understanding it

  • @EvgenyOrekhov
    @EvgenyOrekhov 6 หลายเดือนก่อน +126

    Even better: use dvb/svb/lvb.
    These are called "logical units", and they will respect the writing mode.
    "b" stands for "block", which is the dimension perpendicular to the flow of text within a line, i.e., the vertical dimension in horizontal writing modes, and the horizontal dimension in vertical writing modes.

    • @msweblearner
      @msweblearner 5 หลายเดือนก่อน +1

      Thanks

    • @Pavel555
      @Pavel555 4 หลายเดือนก่อน +3

      It's just a different use case, I assume? The video describes a situation when you need an element with 100% height of viewport.

    • @matt42hughes
      @matt42hughes 4 หลายเดือนก่อน +2

      why would you want any element to be 100% height with horizontal writing mode but 100% width when it’s vertical. isn’t that what respecting the writing mode would do?

  • @Glittery_Magic
    @Glittery_Magic 3 หลายเดือนก่อน +4

    I normally ALWAYS have questions when learning. You cover all the nuances so well I have no questions only full clarity. Excellent Ive subscribed.

  • @houssembenothmen7250
    @houssembenothmen7250 6 หลายเดือนก่อน +57

    svh is not just better
    u have to do it as for the performance tests you will always find the CLS (cumulative layout shift) and definetly the dvh may cause problem there in tests

  • @TomasMisura
    @TomasMisura 2 หลายเดือนก่อน +6

    As a casual web developer, it's challenging to keep up with all the changes and recommendations, so I'm grateful that someone like you is undertaking this and providing us with all that information.

  • @bossaddict08
    @bossaddict08 6 หลายเดือนก่อน +21

    You know what, your content is a step above most other channels regardless of content type. Keep doing what you do please. I think you're excellent.

  • @truthteachers
    @truthteachers 6 หลายเดือนก่อน +1

    Love all the short hints and help from you, bro. Shor, simple nd extremely helpful. Keep them coming. I try to give back something whenever i can.

  • @Hataken999
    @Hataken999 6 หลายเดือนก่อน +4

    The timing couldn't be more perfect. I was creating a "Coming Soon" page and when I was working on the mobile version, the footer and hamburger menu sidebar were overflowing with 100vh. I was stuck trying to find a solution, but then I came up with a dynamic vh solution using JavaScript, and it worked really well (even though it took me almost 3 hours to figure it out).
    And now you post a video, showing me a super simple way to fix it 😂😂

  • @aceenterprise
    @aceenterprise 6 หลายเดือนก่อน

    Thank you, I have dealt with the vh problem quite a bit, and didn't know about the new dimensions.

  • @worthsalive
    @worthsalive 6 หลายเดือนก่อน +4

    I think applying transition on the Hight property will take care of the jumps in with dvh. It will be cool if the jump is rather a smooth stretch.

  • @a1white
    @a1white 6 หลายเดือนก่อน

    Useful! Looks like I’ll be switching my vh to svh from now on. Thanks

  • @user-ms5nu1co5q
    @user-ms5nu1co5q 6 หลายเดือนก่อน

    Life saving. I was having headache with it. Thank you soooooo much❤

  • @moonchildCZ
    @moonchildCZ 6 หลายเดือนก่อน

    Thanks Kevin. I had this exact problem and I just skipped it, because I couldn't find the perfect solution. Now this video showed up to me and it's so easy :)

  • @jaimemartin1932
    @jaimemartin1932 5 หลายเดือนก่อน +2

    I just started using dvh to avoid some issues, and now I discover that svh is even better. Thanks.

  • @degagnemarc
    @degagnemarc 6 หลายเดือนก่อน

    Oh ya! Did I struggle with this a while ago till I found those units. Thanks for the reminder.

  • @Wynorrific1
    @Wynorrific1 6 หลายเดือนก่อน +1

    Great content, you helped me learn HTML, CSS and, SCSS. I'm now learning JavaScript. Have a blessing day.

  • @hariskhan2454
    @hariskhan2454 6 หลายเดือนก่อน +2

    Amazing Man... I just had an issue and from 100vh went to 95vh for Mobile view, but now I think I'll use svh for mobile view !

  • @igordasunddas3377
    @igordasunddas3377 6 หลายเดือนก่อน

    I love your videos, Kevin! You're my goto when I want to learn new things about CSS.

  • @deliriumcode
    @deliriumcode 6 หลายเดือนก่อน +1

    Believed or not - one of your most powerful videos. Short and sorts a years of problems. :)

  • @scottonanski4173
    @scottonanski4173 6 หลายเดือนก่อน +9

    In other words, mobile phone developers are screwing us.

    • @abuhurira-max
      @abuhurira-max หลายเดือนก่อน

      yas that happened to me

  • @gargola1754
    @gargola1754 4 หลายเดือนก่อน

    very useful info, thank you Kevin

  • @wwxstackdeveloper
    @wwxstackdeveloper 3 หลายเดือนก่อน

    Thanks for sharing. Im new to your channel and really enjoy your teaching style.

  • @pibbz13
    @pibbz13 6 หลายเดือนก่อน +2

    After you mentioned this svh in an earlier video, i've been in love with it ever since. It's now a staple in all my projects 👍

  • @saptarshimondal7021
    @saptarshimondal7021 6 หลายเดือนก่อน

    Awesome Explanation! Loved It...

  • @RideTheTeacups
    @RideTheTeacups 6 หลายเดือนก่อน

    This is BRILLIANT. Thank you!

  • @isurus2478
    @isurus2478 5 หลายเดือนก่อน

    omg, someone who actually taught me something i didn't know, thanks kev!

  • @guevarraerick
    @guevarraerick 6 หลายเดือนก่อน

    This is awesome! Solves mobile browser UI overlaps

  • @andreasorourke4252
    @andreasorourke4252 6 หลายเดือนก่อน +2

    I'm getting into freelance development and your channel is super helpful!

  • @DrunkenUFOPilot
    @DrunkenUFOPilot 6 หลายเดือนก่อน

    I had no idea about vh, never mind dvh, svh, lvh. Very clear explanations and demo!
    I would subscribe, except I'm already subscribed :)

  • @colindante5164
    @colindante5164 6 หลายเดือนก่อน

    This is awesome!!! Way better than using calc(100vh - computed height of UI element ). Thanks ))

  • @StephenMoreira
    @StephenMoreira 6 หลายเดือนก่อน +2

    God such great content I need to support you like yesterday.

  • @rameenana
    @rameenana 2 หลายเดือนก่อน

    Thanks man. This was helpful.

  • @rabaa9352
    @rabaa9352 6 หลายเดือนก่อน

    As usual, excellent info.. By the way, nice shirt.

  • @JuanMoisesTorrijos
    @JuanMoisesTorrijos 6 หลายเดือนก่อน

    I have been using dvh and didn't realize that it was causing the layout shift, I guess I will be using svh instead. Thanks for the video.

  • @vouagiaz
    @vouagiaz 5 หลายเดือนก่อน

    omg, an actually useful video! thanks!

  • @stefan5673
    @stefan5673 6 หลายเดือนก่อน +5

    Thank you for your Videos

  • @miro_h2o
    @miro_h2o 6 หลายเดือนก่อน

    My No.1 channel for CSS content!

  • @viktorberczeli3009
    @viktorberczeli3009 6 หลายเดือนก่อน

    Great content and a big plus for the Star Wars + the 'too many' tabs in Chrome.😁

  • @sebastianestrada1311
    @sebastianestrada1311 5 หลายเดือนก่อน

    Interesting useful information about css. Thanks a lot.

  • @martinlottering9048
    @martinlottering9048 3 หลายเดือนก่อน

    Thanks for the easy to understand explanation. I used to think these concepts would just be out of reach for me. 🎉 I struggle a bit with html and css. I think it is because I started with winforms and then later xaml.

  • @IhorVyshniakov
    @IhorVyshniakov 5 หลายเดือนก่อน

    Really usefull rules, thank you for informing about these new features of CSS

  • @sharjeelfaiq16
    @sharjeelfaiq16 6 หลายเดือนก่อน

    You've fixed my life. Thanks a lot.

  • @kirillriman3611
    @kirillriman3611 4 หลายเดือนก่อน

    Useful info, thanks

  • @gabydewilde
    @gabydewilde 6 หลายเดือนก่อน +6

    Welcome to another episode of new units to work around issues with old units but have issues of their own. Of course you could also use: bottom but I get that that isn't the point of the exercise.
    We kinda needed a new way to make pages jump up and down now that most of the old methods have been fixed.

    • @Lumiden
      @Lumiden 3 หลายเดือนก่อน

      Not really, these units were just not necessary before mobiles started having a dynamic height.

  • @rand0mtv660
    @rand0mtv660 6 หลายเดือนก่อน +8

    Recently dvh was useful to me for a fixed collapsed menu on mobile. There is no layout shift there because the element is a fixed menu and when I was using vh, bottom of the menu would get cut off in certain cases because of browser UI pushing it down. Using dvh it worked in all cases as I wanted it so that was nice.

  • @katlegomonama5824
    @katlegomonama5824 6 หลายเดือนก่อน +1

    We having that CSS convo , About that time!

  • @dominicdomingo9654
    @dominicdomingo9654 4 หลายเดือนก่อน

    Omg having troubles with this kind of problem THANK YOU BIG SO VERY MUCH!!

  • @septimusforster
    @septimusforster 5 หลายเดือนก่อน

    Mr KP! Awesome, always.

  • @slipoch6635
    @slipoch6635 4 หลายเดือนก่อน

    great video man, thanks

  • @kristofgheyssens3941
    @kristofgheyssens3941 25 วันที่ผ่านมา

    Will certainly try this out. Have been using 95vh or so for mobile to fix this, but it's a bit unpredictable.

  • @pagarevijayy
    @pagarevijayy 3 หลายเดือนก่อน

    good one. i didn't even know this existed. no time to catchup. thanks for this!

  • @deankinyua2365
    @deankinyua2365 4 หลายเดือนก่อน

    you help us so much Powell ........wish i had financial means to support you☺☺☺

  • @refeals
    @refeals 6 หลายเดือนก่อน +1

    love how they made it super trivial to solve a problem that was super annoying to handle

  • @azzazkhansiddiqui
    @azzazkhansiddiqui 6 หลายเดือนก่อน

    Thanks man you saved my day.

  • @Sashad2003
    @Sashad2003 6 หลายเดือนก่อน

    Thanks for the explanation 👍

  • @ismaelrosas1494
    @ismaelrosas1494 4 หลายเดือนก่อน

    Thanks! nice tips!

  • @cachogames
    @cachogames 4 หลายเดือนก่อน

    Great content like always

  • @giuseppebonariva6753
    @giuseppebonariva6753 6 หลายเดือนก่อน +6

    @KevinPowell, in case you are short of ideas for new videos, I would like to understand how you manage the Cumulative Layout Shift (CLS) issues that occur by adding to the page some dynamic elements, fonts, s, etc.

    • @silent_syntax
      @silent_syntax 6 หลายเดือนก่อน +1

      If you are talking about dynamic elements that are loading when the page loads, you could use skeleton loaders like TH-cam does to make up for the space they will take once they fully show up. :)

  • @mfurkankaya
    @mfurkankaya 6 หลายเดือนก่อน

    When I saw the thumbnail, I thought this is absolutely clickbait. What could be better then vh? But this is really great!

  • @PacificDev
    @PacificDev 6 หลายเดือนก่อน

    Love your sweatshirt and the video, of course!

  • @spaceflightquack
    @spaceflightquack 3 หลายเดือนก่อน

    You are a miracle, i just ran in this problem

  • @evansvibetv1237
    @evansvibetv1237 6 หลายเดือนก่อน +4

    I would love to see more videos of javascript from your contents... I love your teachings.

  • @SashenMe
    @SashenMe 6 หลายเดือนก่อน

    Thanks for addressing my question!

  • @user-nw6fd8xn2m
    @user-nw6fd8xn2m 5 หลายเดือนก่อน

    i love you Kevin Powell you are great

  • @hstrinzel
    @hstrinzel 3 หลายเดือนก่อน

    WOW, VERY GOOD! I needed that already years ago! Thank you! Is there some way how to affect FONT SIZE (e.g. much LARGER FONTS on much smaller devices?), or on portrait vs landscape?

  • @shohelrana-dev
    @shohelrana-dev 6 หลายเดือนก่อน

    I am searching for this solution. thank you.

  • @MightBeRasor
    @MightBeRasor 6 หลายเดือนก่อน +8

    I'm building websites with different sections that need to be as tall as the viewport and there are a lot of scroll-based animations. Whenever there is a layout shift it can get pretty laggy because the libraries need to recalculate everything to the new scroll position. I've tried some approaches, but I found that using 100lvh is interesting because the section will always cover the viewport and, with the animations, all the extra height at the bottom of the section is barely noticeable. Anyone have a better alternative?

    • @christian9540
      @christian9540 6 หลายเดือนก่อน +1

      Not sure what you are doing and what you need, but if you want to make full page containers and stick to that even on resize, you can simply just use something anchor like to see what anchor is next to you and scroll to it. Use windows resize and awrtimeout + cleartimeout method to actually delay it to not constantly recalculate on resizing. Make the delay to something like 100ms and then get your current position. Iterate through your predefined anchors and request their position. If you notice being between two anchors you can define a percentage breaking point when to the scroll up or down.
      You can use the values here but they will change instantly. If you want a certain amount of delay or only resize them after window resizing finished, use css variables and fill them by js on windows resize, use settimeout and cleartimeout to add a delay. With var(--var, 100vh) you can also let it work initially and it will be resized very shortly after loading. If you want to reduce the time cause your application takes a moment when loading, you can use cookies to store the value. So when you load site you can check if there this cookie, access it and actually use that as the initial value as well.
      But if you application is that slow, maybe optimizing it is better than adding another workaround.

  • @confused_horse
    @confused_horse 6 หลายเดือนก่อน

    Apparently it's already supported more than 98% by now. Really comes in handy to know about it right now. Working on my first mobile application.

  • @abacealeycagan2896
    @abacealeycagan2896 4 หลายเดือนก่อน

    love you Kevin ❣❣

  • @rusul.994
    @rusul.994 6 หลายเดือนก่อน

    Oh ,thank you so much .. i was suffering from this problem❤

  • @Credi6464
    @Credi6464 6 หลายเดือนก่อน

    I used dvh in one of my projects, it was my first time using it, when i saw the scrolling in mobile i had no idea what was happening, took me some time to discover the issue was being caused by this dynamic heights, and yeah, svh solved the issue

  • @user-bx6ny3bb8p
    @user-bx6ny3bb8p 6 หลายเดือนก่อน

    For me this is useful in media queries since you've mentioned that vh doesn't have problem on desktops but only on mobile view

  • @HG-wu6eb
    @HG-wu6eb 4 หลายเดือนก่อน

    Thank you man!

  • @CodeHerb
    @CodeHerb 6 หลายเดือนก่อน

    Please sir thanks for the wonderful explanation but between (dvh, svh, lvh) which one is more better to use?

  • @daviderichsen9267
    @daviderichsen9267 4 หลายเดือนก่อน

    I like to use an outer element with 100vh to prevent page to shift height, and then use an inner element with 100dvh to adjust the for objects placement in the wiewport.

  • @mefesto_
    @mefesto_ 6 หลายเดือนก่อน +1

    I tried to use 100dvh, but my clients don't like to see layout jump when scrolling the page. I will try to use 100svh :)
    Nice video!

  • @TheBoysMemes123
    @TheBoysMemes123 3 หลายเดือนก่อน

    I was suffocating but after adding dvh instead of vh it works and love from my heart

  • @keenoogodlike
    @keenoogodlike 5 หลายเดือนก่อน

    Best CSS teacher.

  • @TysonBrady
    @TysonBrady 25 วันที่ผ่านมา +1

    I used svh, dvh and lvh for a project a few months ago and during user testing had complaints from everyone using Apple devices because they weren't working properly (like not at all). Never again, at least not for a few years.

  • @nztchris8024
    @nztchris8024 2 หลายเดือนก่อน

    He is just like a gold mine but for CSS stuff! Great videos!

  • @27sosite73
    @27sosite73 6 หลายเดือนก่อน

    thank you Kevin

  • @ahooton
    @ahooton 6 หลายเดือนก่อน +4

    I've just tested this out in my current project... Indeed, for most things, svh seems to work better on mobile than dvh. The one exception is for my background overlay effect, which covers the mobile viewport more accurately when set to dvh.

  • @nikolaicholakov2798
    @nikolaicholakov2798 6 หลายเดือนก่อน

    the best explanation!

  • @seobookpro
    @seobookpro 6 หลายเดือนก่อน

    Anyway Everyone can do they own way of CSS - The Dev Tool is way to test and see what's new and what values and units are included and supported by your Browser Inspect Tool. Especially for CSS - when you type your new or select class or id hit the Tab and you will see all available values for the CSS attribute you want to edit, change or check.

  • @cdrbvgewvplxsghjuytunurqwfgxvc
    @cdrbvgewvplxsghjuytunurqwfgxvc 6 หลายเดือนก่อน

    Awesome, didnt know that!

  • @belnoccio
    @belnoccio 4 หลายเดือนก่อน

    What a life saver 🤩

  • @AlThePal78
    @AlThePal78 6 หลายเดือนก่อน

    Wow I didn't know or realize there was others besides dvh I thought it was only dvh and vh thanks :)

  • @ukpeflynnbright4773
    @ukpeflynnbright4773 5 หลายเดือนก่อน

    Thank you very much

  • @webartem
    @webartem 4 หลายเดือนก่อน

    That’s nice but it’s always worth asking: is it ready for the production?
    I checked caniuse, so looks like there is only one known issue, the major one though:
    Safari 15.6 on macOS has an issue where dvh is larger than expected (242758).

  • @v4ldevrr4m47
    @v4ldevrr4m47 5 หลายเดือนก่อน

    New suscriber, this video or the tittle in this one catch my attention . And Later Here you are! Great content

  • @EugeneKoshelev
    @EugeneKoshelev 6 หลายเดือนก่อน

    Nice! And what do you thimk about using 100% insted?

  • @MarcosEntreAspas1
    @MarcosEntreAspas1 25 วันที่ผ่านมา

    THANK YOU!

  • @NeverCodeAlone
    @NeverCodeAlone 6 หลายเดือนก่อน

    Verz nice video thx a lot!!

  • @nathanconlon738
    @nathanconlon738 6 หลายเดือนก่อน +1

    Wow, this is perhaps *the* most helpful video I've seen on CSS. I'm currently building a UI for my university and the vh was an annoying issue. I'd resorted to something like calc(100vh - 170px) for the height, but I can see that svh is much better. Thank you!

    • @afrographixstudio
      @afrographixstudio 6 หลายเดือนก่อน

      you could have used javascript. by setting your div height equals to -- window.innerHeight+"px" --

  • @MrJettann
    @MrJettann 6 หลายเดือนก่อน +1

    Kevin, I have a question for you, will this fallback work if I use it inside calc function? Or for this purpose I have to use @supports directive and inside of it use my calc?

    • @christian9540
      @christian9540 6 หลายเดือนก่อน

      Fallbacks works if your input is invalid. As long it is invalid it uses the previous value. Actually I am not sure why you are even asking this. You can test your question in a few seconds...

  • @Jay-pp4pk
    @Jay-pp4pk 3 หลายเดือนก่อน

    Thanks man. You save me)

  • @tehoko
    @tehoko 6 หลายเดือนก่อน +5

    I'm definitely going to be using lvh for one thing: full-page background images. With vh or dvh they'll get resized, which isn't a desirable side effect of scrolling. With lvh the image will always stay the same size.

  • @justinoneill2837
    @justinoneill2837 6 หลายเดือนก่อน

    OMG thank you. been trying to find hacks around this for years