Transition to "height: auto;" & "display: none;" Using Pure CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.ค. 2024
  • Find out how to easily transition from “height: 0;” to “height: auto;” and “display: none;” to “display: block;” without any hacks, tricks, or JavaScript, using only new CSS features: calc-size() function, transition-behavior property and @starting-style at-rule.
    🔗 Links
    Demo: codepen.io/ZoranJambor/pen/GR...
    CSS Stickers: stickers.css-weekly.com
    Guide to Logical Properties: • In-Depth Guide to CSS ... Experimental Web Platform features: • How to enable experime...
    📖 Chapters
    00:00 About CSS transitions & demo setup
    01:26 How to transition to height: auto;
    04:06 How to transition from display: none
    04:43 How transition-behavior CSS property works
    06:32 How @starting-style at-rule works
    08:34 Browser support for transition-behavior & @starting-style
    Subscribe to CSS Weekly Newsletter:
    💌 css-weekly.com/
    Help support my channel
    🪧 Buy a CSS sticker pack: stickers.css-weekly.com
    👨‍🎓 Get a course: masteringlinting.com/
    💖 Jouin us on Patreon: / cssweekly
    Keep up-to-date with CSS Weekly:
    🐦 Twitter: / @cssweekly
    🎶 TikTok: / cssweekly
    🎇 Instagram: / cssweekly
    📘 Facebook: / cssweekly
    Keep up to date with what I'm up to:
    👨‍💼 Blog: zoranjambor.com
    💼 LinkedIn: / zoranjambor
    - Zoran Jambor
    #css #csstips
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Thanks Zoran for introducing calc-size and starting-style.
    We can now significantly cut down on JavaScript code and safely eliminate animation libraries by placing the declarations directly in CSS where they belong. good stuff 🙌
    PS: ☝the "extra padding" can be eliminated by adding 'box-sizing: border-box;' to the container.

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

      Indeed! It's so nice to see that all of this can be done natively in CSS. 🙂
      Thanks so much for the box-sizing tip, Daniel! It does work. 🙂

  • @paulh6933
    @paulh6933 27 วันที่ผ่านมา +1

    this is pretty cool!!

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

      Thanks! I'm glad you think so, Paul! 🙂

  • @jugibur2117
    @jugibur2117 27 วันที่ผ่านมา +1

    Thanks, that was a great explanation, especially this "allow-discrete"

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา

      Thank you so much! I'm thrilled to hear you think so! 🙂

  • @user-lf6mx4il1e
    @user-lf6mx4il1e หลายเดือนก่อน +4

    Lorem ipsum dolor 🔥🔥

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

      Sit amet, consectetur. 🙂

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

    Thanks Zoran a very straightforward explanation that I've seen explained recently in a very complicated manner 👍

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

      Thank you so much; I'm incredibly happy to hear this, Tony! It means a lot! 🙏
      Is there any chance you could share where you've seen the other explanation? I'd like to see what I did differently for future videos. You don't have to share it publicly if you're not comfortable with it. 🙂

    • @tonymorin6308
      @tonymorin6308 18 วันที่ผ่านมา

      @@CSSWeekly Hi Zoran, I think what I meant was that your demo (all your demos actually!) focus in on the topic by keeping it simple & focussing in on the actual topic in a nice isolated example to make your point. Personally I find it clearer this way. I've implemented some of your topics to great effect on some of the sites I'm working through on a course I'm taking to enhance the sites I'm writing! Some of the other examples from other really good youtube creators/teachers have taught the topic inside a more complex example where there's more going on than just the core topic. Sometimes I find it less clear when its dressed up in a more complex example.
      I don't need it super dumbed-down, I'm getting the hang of it, but unlike a pure programming language I can get my head around fine, as it's where I came from, I sometimes find HTML & CSS a little baffling at times. I'm in my 50's, did some college back in the day, got my 1st programming job back in 1989 using cobol & old school 4GL procedural languages, & had a 16 year career working in various small and medium sized software houses, moving into OOP & SQL in languages like vb & delphi, before moving off in a different direction. Over the last couple of years I started casually re-engaging with software dev in a hobbyist capacity, out of boredom in my spare time & recently I've been doing more & more HTML, CSS & JS and it's pulling me back in and I'm loving it!
      On a separate topic, I wonder if you could create a CSS nesting video. At the moment I'm working through a great Udemy HTML CSS & JS course, but the course is a couple of years old & not updated to reflect the newer CSS methods you & others deal with. They're still using the classic way of writing CSS , for example, classic padding & margin & not block-level, & header {}, then header nav {}, then header nav ul {}, then header nav ul li {}, then header nav ul li a {}" . I've watched a few videos on nesting but from quite a while back when browser support wasn't as widespread as it is now. I apologise if you have one already, I did look but didn't notice one. I know I'd love seeing a CSSWEEKLY video on this topic, clearly explaining it all. Keep it up mate! 👍

    • @CSSWeekly
      @CSSWeekly  15 วันที่ผ่านมา +1

      Thank you so much for all your insight and compliments, Tony! It really means a lot! 🙏
      Oh, I was working with Cobol at my first programming job, too! It was mainly maintenance on an existing sytem, around 2005. I moved on to Web Development after that. 🙂
      You'll be happy to hear I have a nesting video planned and ready to record. So, hopefully, it will be on the channel in the next two weeks. 🙂

  • @ahmad-murery
    @ahmad-murery หลายเดือนก่อน +4

    I didn't hear about calc-size() and I think it will solve a lot of headaches.
    Thanks Zoran.

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

      Yes, hopefully it will! Thanks, Ahmad! 🙂

    • @ihateidiots9484
      @ihateidiots9484 29 วันที่ผ่านมา +1

      The more css properties you have, the more problems you receive. To solve those new problems new css properties are introduced.

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา +1

      Yes, this might be the case with new features regardless if we're talking about CSS or something entirely different. 🙂
      And I think you might like my quick tip precisely on the subject of solving all CSS problems in one fell swoop: th-cam.com/users/shortsnXpsbTiAGwc

    • @ahmad-murery
      @ahmad-murery 29 วันที่ผ่านมา +1

      @@CSSWeekly Oh, that tip, how can I forget about it 😁🤦‍♂

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

    wow, thanks for sharing

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

      Thank you, Huynh, for watching and commenting! 🙏

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

      @@CSSWeekly keep going :d

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

      Sure thing, I will! 🙏

  • @techwake360
    @techwake360 29 วันที่ผ่านมา +1

    awesome

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      Thanks so much! 🙏

  • @the-nasim
    @the-nasim 25 วันที่ผ่านมา +1

    Thanks a lot. It was pretty hard to do with JS

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

      Indeed, Nasim. It's much easier and nicer to do this with CSS. Thanks for watching and for your comment! 🙏

  • @fitsum
    @fitsum 27 วันที่ผ่านมา +1

    LOL at 8:44 🤣
    very helpful video. thanks

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

      I'm thrilled you think so, Fitsum! 🙂
      But the important question is: did it work? 😊

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

    Awesome video, calc-size was also new to me just recently seen it popping up but looking forward to use it with the new pseudo element ::details-content where I have seen it used with.
    Your should do a follow-up video for @starting-style with the HTML dialog and/or popover with the overlay property.
    One point I would like to point out is you should avoid using transition all

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      Thanks so much for your insight and thoughtful reply, Sean! I really appreciate it! 🙏
      Yes, I will do a few follow-up videos, and the first one, which is nearly done, is on animating the HTML details element. Popover is certainly something I intend to cover soon. 🙂
      You're right about using "all" with transitions. Thanks for pointing it out! 🙏

  • @a_d_z_y__
    @a_d_z_y__ 22 วันที่ผ่านมา +1

    8:40 the actual TH-cam subscribe button glows when you talk about subscribing? 🤯

    • @CSSWeekly
      @CSSWeekly  22 วันที่ผ่านมา

      I've heard that TH-cam does this, but I haven't seen it in action yet. 🤩
      It's pretty cool. As the video has the transcript, they only need to trigger the animation at the timestamp when the "subscribe" word is mentioned. And I really want to play around with this and try to recreate it-maybe even do a video showcasing how it works. 🙂
      But the most important question is: did it work? 🙂

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

    Which CSS-only solution would you recommend that is working across all (major) browsers today?
    My go-to for this is the CSS grid hack (transitioning grid template rows for 0fr to 1fr) but I'm not sure if there is any other solution that cool kids are doing currently? 😅

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา +2

      Thanks for your question, Luka. 🙏
      The CSS Grid approach with fraction units is the only pure CSS solution I'm aware of that works in all major browsers today, so that's exactly what I'd recommend. 🙂

  • @aquaductape
    @aquaductape 29 วันที่ผ่านมา +1

    transition on toggling `visibility` property to "hidden"|"visible" has applied on transition-end by default for a couple of years, it doesn't need transition-behavior: allow-discrete.

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา +1

      Thanks so much for clarifying; I wasn't aware of this. 🙏

    • @aquaductape
      @aquaductape 29 วันที่ผ่านมา +1

      @@CSSWeekly regardless the possibility of transitioning on `display` is very exciting, due to the fact that `visibility` preserves layout geometry of that element, so for non-overlaying elements its not ideal.

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      Indeed it is! 🙂

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

    Have you tried animating a switch from display grid to display flex? Or between different grid layouts?

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      That's a fantastic question! 🙏
      I don't think it's possible. The transition on "display" happens instantly; it just "flips" at the correct time-before the animation starts or after it finishes.
      You can animate changes in CSS Grid, but I haven't explored this yet, so I can't tell to what extent. Animating track sizes is possible, but I'm not sure if that's the case when switching between different grid layouts-at least not with a simple transition or animation. 🤷‍♂️

    • @m12652
      @m12652 29 วันที่ผ่านมา

      @@CSSWeekly sounds to me like it's time to have a play 👍 great video thanks...

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      You're very welcome! 🙂

  • @cleopelte1561
    @cleopelte1561 27 วันที่ผ่านมา +1

    No way, I was just running into that issue working around it with max-width. I accidentally opened my mail client and it showed me the front end focus newsletter where this was linked. Tell me destiny doesn't exist ;)

    • @CSSWeekly
      @CSSWeekly  27 วันที่ผ่านมา +1

      Oh, I'm so thrilled to hear this, Cleo! Something similar happened to me more than once. 🙂
      I appreciate your comment and am happy to hear where and how you found the video. 🙏

    • @cleopelte1561
      @cleopelte1561 27 วันที่ผ่านมา +1

      @@CSSWeekly I have to thank YOU for sharing your knowledge! 🙏 Looking forward to see more content from you 😊

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา

      Thanks so much, Cleo! 🙂

  • @henriquematias1986
    @henriquematias1986 28 วันที่ผ่านมา +3

    CSS is black magic so many tricks just to make some stuff that should work by default in the first place : D why make it easier when you can make it harder

    • @CSSWeekly
      @CSSWeekly  27 วันที่ผ่านมา +1

      Indeed. 🙂
      One of the main challenges with CSS is backward compatibility. You can't just change or update an existing feature, as you might break half of the internet. So we get calc-size() even though most devs would say that calc() should just work like this. 🤷‍♂️

    • @henriquematias1986
      @henriquematias1986 26 วันที่ผ่านมา +1

      @@CSSWeekly i reckon they should
      Make something like “css2” and let people option in by adding some tag to their CSS file or something.
      And then they should make it just work, no weird hacks 😂
      Like how hard it is to make 100% height on a div actually take 100% height of the screen without having to change body!
      Or how many years we will be adding “css reset” on websites.
      The current situation is a joke 😅

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา +1

      This suggestion sounds reasonable, Henrique. But I'm not sure it's feasible, as we don't really have clear versions of CSS since CSS3; there are just several different specs in different stages. 🤷‍♂️
      It might be an even bigger mess if you needed to specify which version of the 'height' property you want to use. 🙂

    • @henriquematias1986
      @henriquematias1986 26 วันที่ผ่านมา +1

      @@CSSWeekly bring .swf back! 🍭

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา

      Oh, that'd be swell! 🙂
      I used to create websites (or web experiences) in Flash / ActionScript 3.0 - it is only with jQuery that I realized we'd be able to do this natively on the web. But I never even imagined that it would be possible without JavaScript. 🤯

  • @Voltra_
    @Voltra_ 28 วันที่ผ่านมา +1

    IMHO they should just allow auto to act like calc-size(auto) out of the box without having to write it explicitly

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

      Yes, this would be ideal. According to the spec, calc-size() was added "for both practical and backward-compatibility reasons." 🙂

  • @shawn-skull
    @shawn-skull 29 วันที่ผ่านมา +2

    The transition looks weird
    I'd prefer the Kevin Powell solution

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา +1

      What exactly do you mean by weird, Shawn? 🤔
      Yes, Kevin's solution (I assume you're talking about CSS Grid with fr units) is the only pure CSS solution that currently works cross-browser, so it's certainly a better option right now. 🙂

  • @FelquisGimenes
    @FelquisGimenes 27 วันที่ผ่านมา +1

    What's the feature flag name ?

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา +1

      Thanks for your question, Felquis!
      It's "Experimental Web Platform features" flag. You can find it in if you open "chrome://flags" 🙂

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

    great tutorial.
    You won a subscriber from Afghanistan.
    Please pray for our country to get rid of terrorists talibans.

    • @CSSWeekly
      @CSSWeekly  23 วันที่ผ่านมา

      Thank you, Shah, and welcome to CSS Weekly! 👋
      I hope you and your family are safe, that you'll always be safe, and that we, as humanity, find the strength and will to do away with violence and war once and for all. ❤️

  • @johnconnor9787
    @johnconnor9787 28 วันที่ผ่านมา +1

    Nice. Pretty cumbersome feature though...

    • @CSSWeekly
      @CSSWeekly  27 วันที่ผ่านมา +1

      Yes, ideally, it would just work with 'height: auto;' 🙂
      Thanks for watching and commenting, John! 🙏

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

    "...but not in Firefox" - no surprise there

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

      They're actively working on it, hooray.

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

      Thanks for sharing; I didn't know that! 🙂

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

      Yes, unfortunately. I wouldn't be surprised if they announce that they're switching to Chromium, to be honest. 🥺

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

      ​@@CSSWeeklyBoth Opera and Edge did that. It seems that it's only Firefox left.

    • @jarnalyrkar
      @jarnalyrkar 28 วันที่ผ่านมา +1

      Safari probably will never switch to the blink engine from webkit.

  • @robertholtz
    @robertholtz หลายเดือนก่อน +7

    I highly advise you improve your pronunciation of the word “calc.” Your current pronunciation is bordering on obscene. Great information. Many thanks. Cheers.

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา +2

      Oh, thanks for the kind words and your advice, Robert. 🙏
      I didn't realize it was that bad, but the worst part is that I already have two new videos in the final stages of edit that feature the obscene pronunciation. 😔
      I'll try to improve for the next recordings, and I hope you can bear with my "calc" until then. 🙂

    • @robertholtz
      @robertholtz 28 วันที่ผ่านมา +2

      @@CSSWeekly Thank you for your kind response and thank you also for receiving my comment in the constructive manner that I intended. I just subscribed to make sure I don't miss your future videos. Cheers and all the best to you.

    • @CSSWeekly
      @CSSWeekly  27 วันที่ผ่านมา +1

      I'm thrilled to hear this, Robert! 🙏
      I'm aware that I need to improve in many areas, so I take all suggestions and critiques as gifts. I'm always looking for ways to improve, and when someone points it out directly, they make my job easier. 🙂

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

      Cock size was unexpected for me too
      I’m sorry hahaha great video btw

    • @CSSWeekly
      @CSSWeekly  26 วันที่ผ่านมา +1

      Oh no! That's what it sounds like? 🙊😔

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

    Moire

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

      I'm not sure I understand what you mean. 🙂

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

      @@CSSWeekly It's a bit distracting -- the moire effect that's visible on the shirt you're wearing ;)

    • @CSSWeekly
      @CSSWeekly  29 วันที่ผ่านมา

      Oh, ok, I understand. Thanks so much for pointing it out. 🙏
      I guess it's time to get a better camera. Or at least a better shirt. 🙂