css - 将 Bootstrap Dropdown 置于最前面

标签 css twitter-bootstrap twitter-bootstrap-3 z-index

我有以下 dom 树:

<ul class="nav">
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3 That Has a List</li>
    <ul>
         <li class="sidebar-search">
              <div class="input-group custom-search-form">
                   <input type="text" class="form-control" ng-model="searchText" placeholder="Αναζήτηση...">
                   <span class="input-group-btn">
                        <div class="dropdown">
                            <a id="toolsDrop" href="" role="button" class="dropdown-toggle btn btn-primary" data-toggle="dropdown" style="padding: 6px 6px 6px 8px;">Filters&nbsp;&nbsp;&nbsp;<b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu" style="min-width: 0; top: 34px; left: -20px;">
                                    <li>Filter1</li>
                                    <li>Filter2</li>
                                    <li>Filter3</li>
                                    <li>Filter4</li>
                            </ul>
                        </div>
                   </span>
              </div>
         </li>
         <li>
              <ul class="nav nav-second-level sidebar-device-list">Another list that gets filtered by the dropdown and thus, changes size
              </ul>
         </li>
    </ul>
    <li>Item4</li>
    <li>Item5</li>
</ul>

正如您在这些图片中看到的:

Dropdown Example Dropdown not in foreground

,因为 <div class="dropdown">在列表中的div下,如果有下拉按钮的列表元素太小,其他列表项将呈现在下拉菜单上方。我尝试将下拉菜单的 z-index 设置为 99999 但它不起作用,因为 z-indexes 的工作方式(假设元素有不同的父元素,它们处于不同的堆叠顺序/范围 as shown in this article ) .

除了将下拉菜单的定位设置为 fixed 之外,还有什么办法吗? , 将其显示在列表的其余部分上方? (我不希望它高于页面中的所有内容,只是高于父 ul 的其余元素。

最佳答案

最后我想起了原因:

父元素有overflow-y: hidden

将其设置为 initial/visible,然后将显示下拉列表。

关于css - 将 Bootstrap Dropdown 置于最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34130790/

相关文章:

html - SVG 中的居中背景图像

html - Bootstrap 按钮不居中

html - Bootstrap 3 按钮组

javascript - 如何使用 bootstrap 创建一个带有带有标签的复选框列表的下拉菜单?

CSS 垂直菜单 - 菜单项在子菜单悬停时进入非悬停状态

html - 表格中的电子邮件模板较小的表格

html - 多行 anchor 链接 CSS

css - 使用标签元素时,输入组插件高度无法正常工作

javascript - ng-click 与 Bootstrap 评级

html - Bootstrap 3 中带有容器流体和容器的网格