【问题标题】:Bootstrap Button Drop Down pops up above divBootstrap Button Drop Down 在 div 上方弹出
【发布时间】:2018-03-26 15:48:50
【问题描述】:

我希望列表下拉到按钮下方,但我的下拉列表不会一直落在按钮下方,而不是一直位于它现在出现的第一个 div 上。

HTML

    <div class="categories row" id = "secondDiv">
      <div class = "col-md-4 header text-center"> 
        <p id = "columnOne"> Find Your Favorite Celebrity </p>
         <div class="dropdown-container">
            <button class="btn btn-secondary dropdown-toggle btn-outline-danger btn-lg dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> JUST
            <span class="caret"></span></button>
                  <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                    <a class="dropdown-item" href="#">Justin Bieber <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Taylor Swift <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Jay Z <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Beyonce <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Rihanna <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Ariana Grande <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                    <a class="dropdown-item" href="#">Cherie Lum <input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"></label> </a>
                  </div>
          </div> 
      </div>

CSS

.dropdown-container {
位置:相对; }

.dropdown-menu { 位置:绝对;最高:100%; /* 底部 按钮 /margin-left: -100px; / 更多在左边 */ }

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    这是你要找的吗?

    使用的 CSS 是

    .dropdown-container {
      position: relative;
    }
    
    .dropdown-menu {
      position: absolute;
      top: 100%;
      left: 0px;
    }
    
    .dropdown-menu a {
      display: block;
    }
    
    .dropdown-container {
      position: relative;
      display: inline-block;
    }
    

    JSFiddle Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 2011-02-17
      • 1970-01-01
      • 2016-02-11
      • 2020-05-13
      • 2023-03-17
      • 2015-12-31
      相关资源
      最近更新 更多