This question originated from a message on Nuggets. A friend asked, why is the height transition animation of the following code invalid? The pseudo code is probably like this: { height: unset; transition: all 0.3s linear; will-change: height; &.up { height: 0; } &.down { height: unset; } } If we restore it to an actual demo, the effect is probably like this (the essential idea is to switch uh-huh? It's very strange. I clearly set The effect we expect is as follows: Transition does not support height: auto When the above code is set to Looking at the specification, the reason is that CSS transition does not support changes in the element's height to auto. If you replace the above { &.up { height: 0; } &.down { - height: unset; + height: 500px; } } However, we also hope to achieve dynamic height transition. Is there no other way? Cleverly use max-height to adapt to dynamic height Hey, here is a very interesting little trick. Since Let's modify the above code, replace { max-height: 0; transition: max-height 0.3s linear; &.up { max-height: 0; } &.down { max-height: 1000px; } } Let's estimate the maximum height of the actual container. Since CodePen Demo -- the height property transition unwork Minor flawsThe overall effect is still very nice, of course, there may be two small flaws,
Because the original expansion animation was expected to stretch the height of the container to 1000px in 1 second, but it actually stopped at 200px, so the animation time was only 0.2 seconds. To sum up, the method is a good one, but specific analysis is required when it is used. This is the end of this article about the implementation of CSS dynamic height transition animation effect. For more related CSS height transition animation content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Using trap to perform environment cleanup before graceful shutdown of docker container
>>: HTML implements a fixed floating semi-transparent search box on mobile
Table of contents Creating an SSL Certificate 1. ...
MySQL green version setting code, and 1067 error ...
Migration is unavoidable in many cases. Hardware ...
How to change the MySQL database directory locati...
The effect shows that two browsers simulate each ...
Table of contents summary Basic Example motivatio...
Table of contents 1. Backup 1.1 Fully prepared 1....
The PC version of React was refactored to use Ama...
Table of contents 1. Regular expression creation ...
Preface This article mainly introduces the releva...
Table of contents Index Model B+Tree Index select...
Preface: This article mainly introduces the query...
Each time tomcat is started, the following log fi...
1. Log in to MySQL database mysql -u root -p View...
Problem Description After installing Qt5.15.0, an...