我正在尝试使用CSS转换进行<ul>
向下滑动。
<ul>
从height: 0;
开始。在悬停时,高度设置为height:auto;
。然而,这导致它简单地出现,没有过渡,
如果我从height: 40px;
到height: auto;
,然后它会滑到height: 0;
,然后突然跳到正确的高度。
如果不使用JavaScript,我还能怎么做?
#child0 {height: 0;overflow: hidden;background-color: #dedede;-moz-transition: height 1s ease;-webkit-transition: height 1s ease;-o-transition: height 1s ease;transition: height 1s ease;}#parent0:hover #child0 {height: auto;}#child40 {height: 40px;overflow: hidden;background-color: #dedede;-moz-transition: height 1s ease;-webkit-transition: height 1s ease;-o-transition: height 1s ease;transition: height 1s ease;}#parent40:hover #child40 {height: auto;}h1 {font-weight: bold;}
The only difference between the two snippets of CSS is one has height: 0, the other height: 40.<hr><div id="parent0"><h1>Hover me (height: 0)</h1><div id="child0">Some content<br>Some content<br>Some content<br>Some content<br>Some content<br>Some content<br></div></div><hr><div id="parent40"><h1>Hover me (height: 40)</h1><div id="child40">Some content<br>Some content<br>Some content<br>Some content<br>Some content<br>Some content<br></div></div>