我有一个bootstrap 4下拉菜单,它位于bootstrap手风琴的主体内:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<div class="accordion mb-3" id="testAccordion">
<div class="card">
<div class="card-header" id="accordionAHeading">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#accordionACollapse">
Lalala
</button>
</h2>
</div>
<div id="accordionACollapse" class="collapsed collapse show" data-parent="#testAccordion">
<div class="card-body">
<h5>Lalala</h5>
<div class="dropdown" id="addElementDropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="addElementDropdownButton" data-toggle="dropdown">Dropdown</button>
<div class="dropdown-menu" aria-labelledby="addElementDropdownButton">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
<a class="dropdown-item" href="#">Item 3</a>
<a class="dropdown-item" href="#">Item 4</a>
<a class="dropdown-item" href="#">Item 5</a>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="accordionBHeading">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#accordionBCollapse">
Test
</button>
</h2>
</div>
<div id="accordionBCollapse" class="collapse collapsed" data-parent="#testAccordion">
<div class="card-body">
<h5>Test</h5>
<div class="dropdown" id="addElementDropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="addElementDropdownButton" data-toggle="dropdown">Dropdown</button>
<div class="dropdown-menu" aria-labelledby="addElementDropdownButton">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
<a class="dropdown-item" href="#">Item 3</a>
<a class="dropdown-item" href="#">Item 4</a>
<a class="dropdown-item" href="#">Item 5</a>
</div>
</div>
</div>
</div>
</div>
</div>
不幸的是,下拉菜单位于手风琴后面。我已经尝试过向手风琴和卡片中添加一些包含position: relative
的样式,以及不同的z-index
值,但是没有机会。有什么想法吗?
更新:我已将代码段粘贴到tryit editor
中答案 0 :(得分:3)
这是因为在您的卡类中添加了隐藏的溢出内容。将此添加到您的CSS
.accordion .card {
overflow: inherit;
}
答案 1 :(得分:2)
您必须覆盖为下拉列表自动生成的CSS。添加以下CSS:
.dropdown-toggle {
float: left;
}
.dropdown-menu.show {
position: relative !important;
clear: both;
margin-top: 0;
transform: none !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<div class="accordion mb-3" id="testAccordion">
<div class="card">
<div class="card-header" id="accordionAHeading">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#accordionACollapse">
Lalala
</button>
</h2>
</div>
<div id="accordionACollapse" class="collapsed collapse show" data-parent="#testAccordion">
<div class="card-body">
<h5>Lalala</h5>
<div class="dropdown" id="addElementDropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="addElementDropdownButton" data-toggle="dropdown">Dropdown</button>
<div class="dropdown-menu" aria-labelledby="addElementDropdownButton">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
<a class="dropdown-item" href="#">Item 3</a>
<a class="dropdown-item" href="#">Item 4</a>
<a class="dropdown-item" href="#">Item 5</a>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="accordionBHeading">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#accordionBCollapse">
Test
</button>
</h2>
</div>
<div id="accordionBCollapse" class="collapse collapsed" data-parent="#testAccordion">
<div class="card-body">
<h5>Test</h5>
<div class="dropdown" id="addElementDropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="addElementDropdownButton" data-toggle="dropdown">Dropdown</button>
<div class="dropdown-menu" aria-labelledby="addElementDropdownButton">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
<a class="dropdown-item" href="#">Item 3</a>
<a class="dropdown-item" href="#">Item 4</a>
<a class="dropdown-item" href="#">Item 5</a>
</div>
</div>
</div>
</div>
</div>
</div>