2016-11-28 6 views
1

У меня есть простой div, который имеет высоту и максимальную высоту, равную 10px. Когда я навис над ним, он должен расширяться до полной высоты div, и когда я ухожу, он должен сжиматься до 10 пикселей.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; ваш код. он ll делает высоту 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