动画下拉菜单 Bootstrap 4

新手上路,请多包涵

下拉菜单在引导程序(4.0)中的原生方式不是动画的。我怎样才能让它像折叠时导航栏一样“滑动”打开?

值得注意的是,下拉菜单位于导航栏中。见下文代码; https://www.codeply.com/go/JKj5onR3ug

 <nav class="navbar navbar-dark bg-dark">
  <a class="navbar-brand" href="#">Never expand</a>
  <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="navbar-collapse collapse" id="navbarsExample01" style="">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
        <div class="dropdown-menu" aria-labelledby="dropdown01">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

原文由 Michael Ruta 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 911
1 个回答

我喜欢这个。简单又好!

 .dropdown-menu {
   display: block;
   opacity: 0;
   padding: 0;
   max-height: 0;
   overflow: hidden;
   transition: all .3s ease-in;
}
 .dropdown-menu.show {
   max-height: 500px;
   opacity: 1;
   padding: 0.5rem 0;
}

原文由 Nico 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏