我怎样才能过渡高度:0;高度:自动;使用CSS?
P粉461599845
P粉461599845 2023-08-27 11:59:03
[CSS3讨论组]

我正在尝试使用 CSS 过渡使

    向下滑动。


      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>


P粉461599845
P粉461599845

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号