The simple trick to transition from height 0 to auto with CSS

The simple trick to transition from height 0 to auto with CSS

Kevin Powell

1 год назад

205,513 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Action
Action - 14.09.2023 21:43

For some reason I can't get this to work for links. The links in my child element are still clickable and if they have a border property, that border is visible.

Ответить
Younes Akab
Younes Akab - 09.09.2023 22:30

the transition didnt work

Ответить
pavan challa
pavan challa - 09.09.2023 14:09

thanks kevin really helped me alot

Ответить
prosper jaja
prosper jaja - 05.09.2023 02:10

Can one do this in the context of width? i.e transitioning width. Say cards stack on top of each other and you need it to show its actual width when clicked on.

Ответить
dan me
dan me - 04.09.2023 06:43

on chrome right now the container and the contents do not expand at the same time, use a few lines for content, set a different background for the contents and increase the transition duration

Ответить
jayanth
jayanth - 03.09.2023 22:08

Man i love how this guy seems so happy when exploring new things.

Ответить
The Cyber Hobbit
The Cyber Hobbit - 03.09.2023 03:09

Wow.... "We have the technology" finally. One of the longest CSS mysteries has been solved. Bravo.

Ответить
German Martirosyan
German Martirosyan - 02.09.2023 21:57

Kevin, thank you! You are the best css advocate in world wide web) Watch your channel with pleasure!)

Ответить
Andrea Dragotta
Andrea Dragotta - 02.09.2023 00:09

I would want to give you 1000 thumbs up for this! Awesome trick!!

Ответить
Dmitry Lebedev
Dmitry Lebedev - 31.08.2023 14:43

that is cool, thank you!) And what is if we need to start for example with 4rem and expand to 100%?

Ответить
Z Yin
Z Yin - 28.08.2023 22:36

But I thought we should never teach people to animate anything other than opacity and transform?

Ответить
Crown Control
Crown Control - 28.08.2023 17:51

What if i have <ul> i code?

Ответить
Crown Control
Crown Control - 28.08.2023 13:30

JESUS!
SICK SOLUTION!

Ответить
Nephi
Nephi - 25.08.2023 16:47

I was so happy to see this when you first published it and I just used it again today. As a matter of fact, I made it a collection of helper classes that I can apply to anything and I plan to replace all of my collapsible blocks with this.

Ответить
Rohit Tripathi
Rohit Tripathi - 23.08.2023 05:57

Can I build this using details and summary tag instant of using div? I have created div.Parent (flex, col) > details > summary + p and I am using before content "\Unicode" with position, I just wanted to know it's not a right approach to build expand drop-menu?

Ответить
mandokir
mandokir - 23.08.2023 00:34

And if you have any margins or padding, you just lose.

Ответить
Enes
Enes - 17.08.2023 13:13

Thank you so much. I needed that and now my accordion menu works perfectly.

Ответить
Sebastian Manuelli
Sebastian Manuelli - 17.08.2023 06:21

Simply amazing

Ответить
Sergej Kukshaus
Sergej Kukshaus - 15.08.2023 22:33

This is crazy! I've been struggling today with exact this requirement. Ending up with transitioning the min-height from 0 to e.g. 400px and setting the height from 0 to auto. I've also added the scaleY() transform, which actually looks very awesome. But from my point of view, this is a much cleaner solution than setting the min-height to a random value. Thanks for sharing this cool trick.

Ответить
wichtel
wichtel - 14.08.2023 20:01

Thank you very much for this. I'd rather have a "useless" div than unnecessary JavaScript. You just saved me a good bit of ugly JavaScript! 🙂

Ответить
Willian Damasceno
Willian Damasceno - 07.08.2023 23:08

This is the most usefull video of all times, thank you!

Ответить
Fatih Bulut
Fatih Bulut - 01.08.2023 15:45

You are a brilliant man, thank you so much.

Ответить
Bartek
Bartek - 29.07.2023 10:24

Amazing, thanks a lot!

Ответить
Leonardo Barrochello
Leonardo Barrochello - 28.07.2023 20:34

how can i do in my case? i want a paragraph to expand or collapse the content when i click on see more/see less button . i find difficult to apply animation for this

Ответить
Denis Kononov
Denis Kononov - 28.07.2023 19:52

Thanks, saved my day.

Ответить
wiki boot
wiki boot - 27.07.2023 06:57

Thank you for this video, how can it work on mobile? It is a great solution... but for mouse only? I tried a lot cursor-set but without success (surely I'm doing something wrong).

Ответить
LucaPi
LucaPi - 25.07.2023 19:43

OMG. How have I never thought of this before??? So much time wasted

Ответить
Heniu
Heniu - 20.07.2023 00:45

This is great, but actually I don't understand - why do you need inner div with overflow: hidden? Why it won't work without it?

Ответить
Jahid Hasan Jibon
Jahid Hasan Jibon - 19.07.2023 10:02

awesome.

Ответить
Novi+
Novi+ - 18.07.2023 20:02

Awesome! Thanks, buddy.

Ответить
heitoralthmann
heitoralthmann - 12.07.2023 18:01

Thanks Kevin! Been looking for something like this for a long time!

Ответить
Tejas Nikam
Tejas Nikam - 11.07.2023 22:41

Wow

Ответить
m12652
m12652 - 11.07.2023 18:49

Great stuff… but… I’m building in Svelte and though the example works perfectly as is, I modified it to use a css custom prop and added a button to the page to toggle a —grid-template-rows prop between 0fr and 1fr. even though the hover code simply sets the prop same as the button as soon as I use the button it stops transitioning smoothly, like there was no transition. It’s really odd… first the hover works fine then I click the button and after that both hover and click no longer transition smoothly. Even if I set the transition time in the hover css it’s still stops working after clicking the button…

Ответить
Petar Kolev
Petar Kolev - 11.07.2023 09:06

The passion everyone can see with you're doing the videos with is priceless, that makes the videos even more valuable!

Ответить
Gabriel Mineiro
Gabriel Mineiro - 10.07.2023 22:57

This is so SO HELPFUL! My collapsible components are now perfect! Had to use some javascript to change overflow to visible once the transition is complete, because I'm using dropdown inside, but the overall result is top notch! Thank you!

Ответить
ZX Presh
ZX Presh - 10.07.2023 04:27

Can anyone tell me if the content in the "hidden" grid element (0fr tall) remains visible to screen readers? If so, this potentially solves a further accessibility problem... I think?!
Either way, is having an <a> tag handle the open/close state directly before the "hidden" element enough to make it accessible? 🤔

Ответить
Marcelo Barros
Marcelo Barros - 04.07.2023 18:47

Really useful! Thanks! 🙂

Ответить
Ned Alturas
Ned Alturas - 28.06.2023 15:15

Been scratching my head as I tried to do it with javascript. Gladly the Algorithm showed this video. Thanks Kevin!

Ответить
themightysapien
themightysapien - 27.06.2023 12:59

This should be the official technique :D. Now you only have to find a solution for display transitions and you name will be immortalized in css history.

Ответить
Norbert Szorc
Norbert Szorc - 23.06.2023 14:38

This is absolutely amazing! I was struggling with this issue for a while. This solution is amazingly creative and simple. Thank you <3

Ответить
Dukeeehhh
Dukeeehhh - 23.06.2023 09:36

Would it be possible to also make the content "slide out" from top to bottom, without using any fixed values? So that it doesn't look like it was already there, but hiding underneath the panel-title.

Ответить
Just The Things I Think
Just The Things I Think - 18.06.2023 15:47

Lifesaver.

Ответить
A_underflowexception
A_underflowexception - 16.06.2023 17:52

random question , are aria tags required if the html is
already semantic?

Ответить
Max Weir
Max Weir - 16.06.2023 08:16

Could there be any performance issues related to using this approach for an accordion?

Ответить
Hameed M
Hameed M - 14.06.2023 09:42

life saver :D

Ответить
David Světlík
David Světlík - 13.06.2023 17:06

Thank you, it's great, but the fact we have to depend on workarounds like this in 2023 for auto-height transition is just shameful.

Ответить
Ahmed Salah Abdullah
Ahmed Salah Abdullah - 12.06.2023 19:27

ما شاء الله
فعلاً ممتاز كود بسيط حل مشكلة كبيرة

Ответить
Erick Rodríguez
Erick Rodríguez - 05.06.2023 19:13

YES

Ответить