I have a bootstrap 4 drop down menu, that sits within the body of a bootstrap accordion:
<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>
Unfortunately, the dropdown menu is drawn behind the accordion. I've already tried to add some styles containing position: relative
to the accordion and the cards, and also different z-index
-values, but no chance. Any ideas?
UPDATE: I've pasted the snippet into the tryit editor
UPDATE 2: I've also done a screencast of the above code:
Its because there is overflow hidden added to your card class. Add this to your CSS
.accordion .card {
overflow: inherit;
}
You must override the CSS that is auto-generated for the dropdowns. Add the following 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With