css3的transition在设置height:auto时无效
2020/09/16    

css3的transition在设置height:auto时无效

解决办法,设置max-height,overflow:hidden;

demo:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            max-height: 20px;
            transition: all linear .2s;
            overflow: hidden;
        }
        div:hover{
            max-height: 200px;
        }
    </style>
</head>
<body>
    <div>
        fdjal;<br />
        fdjal;<br />
        fdjal;<br />
        fdjal;<br />
        fdjal;<br />
    </div>
</body>
</html>