2016-11-28 7 views
1

私は高さと最大高さが10pxに設定された単純なdivを持っています。私はそれを上に置くとき、それはdivの完全な高さに拡大する必要があります、そして、私はそれを10pxに縮小する必要があります。cssの遷移max-heightが0に戻りません

しかし、私はunhoverたときに、以下のコードは、通過しませんスムーズに0

HTML

<div class="animate"> 
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 
</div> 

CSS

.animate{ 
    font-size:20px; 
    height : 10px; 
    max-height:10px; 
    width: 100px; 
    overflow:hidden; 
    -webkit-transition: all 0.5s ease-in-out; 
    -moz-transition: all 0.5s ease-in-out; 
    -ms-transition: all 0.5s ease-in-out; 
    -o-transition: all 0.5s ease-in-out; 
    transition: all 0.5s ease-in-out; 
} 
.animate:hover{ 
    height:auto; 
    max-height:1000px; 
} 

https://jsfiddle.net/3hfxg6he/2/

答えて

5

からheight:10px;を削除しますあなたのコード。高さを10pxにし、オーバーフロー隠しにします。アニメーションがうまくいかない理由ですmax-heightプロパティの詳細についてはthis link

.animate{ 
 
    font-size:20px; 
 
    max-height:10px; 
 
    width: 100px; 
 
    overflow:hidden; 
 
    -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -ms-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 
.animate:hover{ 
 
    height:auto; 
 
    max-height:1000px; 
 
}
<div class="animate"> 
 
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 
 
</div>

+0

たぶん '最大の高さに従ってください:なし;'むしろ1000px' 'よりも? – Rounin

+1

divをアニメーション化しません。どのようにアニメートする必要があるかわからないためです。私たちはいくつかの 'max-height'値を与えるべきです – jafarbtech

+0

ああ、それは本当に知っておくと便利です。ありがとうございました! – Rounin

関連する問題