【问题标题】:How to align a Bootstrap Dropright menu such that it opens upwards (unlike the default downwards direction)?如何对齐 Bootstrap Dropright 菜单,使其向上打开(与默认的向下方向不同)?
【发布时间】:2019-07-27 17:48:11
【问题描述】:

我的下拉菜单正确地向右下降,但向下,这导致它隐藏在我的页面下。我希望它向上而不是向下打开。

我尝试摆弄 CSS,将 bottom:0 添加到 dropdown-menu,但没有奏效。我还尝试在dropup 中嵌套dropdown-menu-right,但显示的菜单与按钮不一致(它位于右上角的对角线)。

这是我的下拉列表的完整代码:

              <div class="dropright" style="position: relative;">
                <button class="btn btn-primary btn-block" style="font-size: large;" onblur="this.nextSibling.style.display='none'" onclick="this.nextSibling.style.display='block'" >
                  <img src="/assets/Images/Avatar.jpg"  class="rounded-circle" style="height:30px;width:30px; padding: 0;" alt="Avatar">
                </button>
                <div class="dropdown-menu" style="position: absolute;">
                  <a class="dropdown-item" href="">Action</a>
                  <a class="dropdown-item" href="">Another action</a>
                  <a class="dropdown-item" href="">Something else here</a>
                  <a class="dropdown-item" href="">Something else here</a>
                </div>
              </div>

This是我想要的

This 是问题

【问题讨论】:

    标签: html css drop-down-menu bootstrap-4


    【解决方案1】:

    你期待吗

    .dropup .dropdown-menu {
        top: auto;
        left: 35px;
        bottom: 100%;
        margin-bottom: -36px !important;
     }
    <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <div class="container">
      <h2>Dropdowns</h2>
      <p>The .dropup class makes the dropdown menu expand upwards instead of downwards:</p>
      <br><br><br>
      <div class="dropup">
        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
        <span class="caret"></span></button>
        <ul class="dropdown-menu">
          <li><a href=" ">APPLICATIONS</a></li>
            <li class="divider"></li>
    
          <li><a href=" ">Bitbucket</a></li>
          <li><a href="#">Jira </a></li>
        </ul>
      </div>
    </div>

    【讨论】:

    • 确实如此。但我相信这个在响应式设计中使用起来并不容易。我想要一个针对我的问题的引导解决方案,它也适用于响应式设计。
    • 我们可以通过编写媒体查询来实现它,告诉我限制条件(在哪个设备(笔记本电脑、平板电脑...)你没想到的 dropup 的大小)。
    • 主要是台式机和笔记本电脑。我希望下拉菜单出现在按钮旁边(向右),与底部对齐。正如您的 sn-p 中显示的那样。我只想让 t 做出响应,而不是与按钮保持一定的像素距离。
    • 哦,我想我刚刚想通了。以下css对我有用: .dropup .dropdown-menu { top: auto;左:100%;底部:0%; } 感谢您的帮助
    • 如果您认为我的解决方案有助于获得答案,那么您可以通过点击答案旁边的勾号来接受我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    相关资源
    最近更新 更多