編碼的世界 / 優質文選 / 生涯

css3實現高度從固定到高度自適應的過渡動畫


2022年5月19日
-   

去年做過一個這樣的動畫效果,然後今年又做了一次,今年做的時候突然發現想不起來了,摳鼻尷尬 百度了下找到了方法,在此記錄下! 效果圖如下 代碼如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.box {
max-height: 120px;
min-height: 120px;
overflow: hidden;
transition: max-height ease-out 0.2s;
border: 1px solid red;
width: 200px;
}
.box:hover {
max-height: 500px;
transition: max-height ease-in 0.2s;
}
</style>
</head>
<body>
<div class="box">
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
<p>123132123132123</p>
</div>
</body>
</html>

熱門文章