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

  Рет қаралды 10,037

CSS Weekly

CSS Weekly

Күн бұрын

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

Пікірлер: 85
@MyDpop
@MyDpop Ай бұрын
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 Ай бұрын
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. 🙂
@jugibur2117
@jugibur2117 Ай бұрын
Thanks, that was a great explanation, especially this "allow-discrete"
@CSSWeekly
@CSSWeekly Ай бұрын
Thank you so much! I'm thrilled to hear you think so! 🙂
@paulh6933
@paulh6933 Ай бұрын
this is pretty cool!!
@CSSWeekly
@CSSWeekly Ай бұрын
Thanks! I'm glad you think so, Paul! 🙂
@tonymorin6308
@tonymorin6308 Ай бұрын
Thanks Zoran a very straightforward explanation that I've seen explained recently in a very complicated manner 👍
@CSSWeekly
@CSSWeekly Ай бұрын
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 Ай бұрын
@@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 29 күн бұрын
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. 🙂
@user-lf6mx4il1e
@user-lf6mx4il1e Ай бұрын
Lorem ipsum dolor 🔥🔥
@CSSWeekly
@CSSWeekly Ай бұрын
Sit amet, consectetur. 🙂
@ahmad-murery
@ahmad-murery Ай бұрын
I didn't hear about calc-size() and I think it will solve a lot of headaches. Thanks Zoran.
@CSSWeekly
@CSSWeekly Ай бұрын
Yes, hopefully it will! Thanks, Ahmad! 🙂
@ihateidiots9484
@ihateidiots9484 Ай бұрын
The more css properties you have, the more problems you receive. To solve those new problems new css properties are introduced.
@CSSWeekly
@CSSWeekly Ай бұрын
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: kzfaq.infonXpsbTiAGwc
@ahmad-murery
@ahmad-murery Ай бұрын
@@CSSWeekly Oh, that tip, how can I forget about it 😁🤦‍♂
@HuynhLuong227
@HuynhLuong227 Ай бұрын
wow, thanks for sharing
@CSSWeekly
@CSSWeekly Ай бұрын
Thank you, Huynh, for watching and commenting! 🙏
@HuynhLuong227
@HuynhLuong227 Ай бұрын
@@CSSWeekly keep going :d
@CSSWeekly
@CSSWeekly Ай бұрын
Sure thing, I will! 🙏
@SeanGrimLink
@SeanGrimLink Ай бұрын
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 Ай бұрын
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! 🙏
@techwake360
@techwake360 Ай бұрын
awesome
@CSSWeekly
@CSSWeekly Ай бұрын
Thanks so much! 🙏
@the-nasim
@the-nasim Ай бұрын
Thanks a lot. It was pretty hard to do with JS
@CSSWeekly
@CSSWeekly Ай бұрын
Indeed, Nasim. It's much easier and nicer to do this with CSS. Thanks for watching and for your comment! 🙏
@fitsum
@fitsum Ай бұрын
LOL at 8:44 🤣 very helpful video. thanks
@CSSWeekly
@CSSWeekly Ай бұрын
I'm thrilled you think so, Fitsum! 🙂 But the important question is: did it work? 😊
@LukaPeharda
@LukaPeharda Ай бұрын
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 Ай бұрын
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. 🙂
@m12652
@m12652 Ай бұрын
Have you tried animating a switch from display grid to display flex? Or between different grid layouts?
@CSSWeekly
@CSSWeekly Ай бұрын
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 Ай бұрын
@@CSSWeekly sounds to me like it's time to have a play 👍 great video thanks...
@CSSWeekly
@CSSWeekly Ай бұрын
You're very welcome! 🙂
@aquaductape
@aquaductape Ай бұрын
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 Ай бұрын
Thanks so much for clarifying; I wasn't aware of this. 🙏
@aquaductape
@aquaductape Ай бұрын
@@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 Ай бұрын
Indeed it is! 🙂
@a_d_z_y__
@a_d_z_y__ Ай бұрын
8:40 the actual KZfaq subscribe button glows when you talk about subscribing? 🤯
@CSSWeekly
@CSSWeekly Ай бұрын
I've heard that KZfaq 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? 🙂
@cleopelte1561
@cleopelte1561 Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@CSSWeekly I have to thank YOU for sharing your knowledge! 🙏 Looking forward to see more content from you 😊
@CSSWeekly
@CSSWeekly Ай бұрын
Thanks so much, Cleo! 🙂
@FelquisGimenes
@FelquisGimenes Ай бұрын
What's the feature flag name ?
@CSSWeekly
@CSSWeekly Ай бұрын
Thanks for your question, Felquis! It's "Experimental Web Platform features" flag. You can find it in if you open "chrome://flags" 🙂
@henriquematias1986
@henriquematias1986 Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@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 Ай бұрын
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 Ай бұрын
@@CSSWeekly bring .swf back! 🍭
@CSSWeekly
@CSSWeekly Ай бұрын
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_ Ай бұрын
IMHO they should just allow auto to act like calc-size(auto) out of the box without having to write it explicitly
@CSSWeekly
@CSSWeekly Ай бұрын
Yes, this would be ideal. According to the spec, calc-size() was added "for both practical and backward-compatibility reasons." 🙂
@shawn-skull
@shawn-skull Ай бұрын
The transition looks weird I'd prefer the Kevin Powell solution
@CSSWeekly
@CSSWeekly Ай бұрын
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. 🙂
@Andrey-il8rh
@Andrey-il8rh 5 күн бұрын
It's great and all but calc-size is so new that it's not even on caniuse 😅 Let's hope it won't take browser vendors 5 years to add it to the list of stable features
@CSSWeekly
@CSSWeekly 3 күн бұрын
Indeed, Andrey! 🙂 Browsers are moving a lot faster these days, so hopefully, this will be in the baseline soon. 🙂
@shahfaisal3923
@shahfaisal3923 Ай бұрын
great tutorial. You won a subscriber from Afghanistan. Please pray for our country to get rid of terrorists talibans.
@CSSWeekly
@CSSWeekly Ай бұрын
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 Ай бұрын
Nice. Pretty cumbersome feature though...
@CSSWeekly
@CSSWeekly Ай бұрын
Yes, ideally, it would just work with 'height: auto;' 🙂 Thanks for watching and commenting, John! 🙏
@seba9260
@seba9260 Ай бұрын
"...but not in Firefox" - no surprise there
@Killyspudful
@Killyspudful Ай бұрын
They're actively working on it, hooray.
@CSSWeekly
@CSSWeekly Ай бұрын
Thanks for sharing; I didn't know that! 🙂
@CSSWeekly
@CSSWeekly Ай бұрын
Yes, unfortunately. I wouldn't be surprised if they announce that they're switching to Chromium, to be honest. 🥺
@jenstornell
@jenstornell Ай бұрын
​@@CSSWeeklyBoth Opera and Edge did that. It seems that it's only Firefox left.
@jarnalyrkar
@jarnalyrkar Ай бұрын
Safari probably will never switch to the blink engine from webkit.
@FlyingPenguino
@FlyingPenguino Ай бұрын
Moire
@CSSWeekly
@CSSWeekly Ай бұрын
I'm not sure I understand what you mean. 🙂
@FlyingPenguino
@FlyingPenguino Ай бұрын
@@CSSWeekly It's a bit distracting -- the moire effect that's visible on the shirt you're wearing ;)
@CSSWeekly
@CSSWeekly Ай бұрын
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. 🙂
@robertholtz
@robertholtz Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@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 Ай бұрын
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 Ай бұрын
Cock size was unexpected for me too I’m sorry hahaha great video btw
@CSSWeekly
@CSSWeekly Ай бұрын
Oh no! That's what it sounds like? 🙊😔
CSS Email Obfuscation - Create a Clickable Link
8:14
CSS Weekly
Рет қаралды 969
In-Depth Guide to CSS Logical Properties
22:35
CSS Weekly
Рет қаралды 7 М.
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 18 МЛН
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 21 МЛН
Best father #shorts by Secret Vlog
00:18
Secret Vlog
Рет қаралды 22 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 105 МЛН
We can now transition to and from display: none
21:20
Kevin Powell
Рет қаралды 84 М.
Learn CSS Subgrid in 14 minutes
14:19
Slaying The Dragon
Рет қаралды 62 М.
Single CSS keyframe tricks are magic
52:02
Bad at CSS
Рет қаралды 3,7 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 360 М.
The problems with viewport units
13:23
Kevin Powell
Рет қаралды 356 М.
2 better alternatives to overflow: hidden
11:04
Kevin Powell
Рет қаралды 153 М.
Simplify Your CSS Using :is() and :where() Pseudo-Classes
9:22
CSS Weekly
Рет қаралды 1,5 М.
The Most Important Skill You Never Learned
34:56
Web Dev Simplified
Рет қаралды 176 М.
A new approach to container and wrapper classes
25:27
Kevin Powell
Рет қаралды 248 М.
These CSS PRO Tips & Tricks Will Blow Your Mind!
8:48
Coding2GO
Рет қаралды 80 М.
Телефон-електрошокер
0:43
RICARDO 2.0
Рет қаралды 382 М.
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 3,2 МЛН
Samsung laughing on iPhone #techbyakram
0:12
Tech by Akram
Рет қаралды 432 М.
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 5 МЛН