I've implemented a navbar that includes dropdown nav-items with a mega menu.
The mega menu is set to position:absolute
.
Is there a way to dynamically align the mega menu in the center of the page while using the same component for all nav-items?
Check out the Code Sandbox demo
.dropdown-menu {
position: absolute;
width: 400px;
height: 300px;
}
.nav-item {
margin-left: 60px;
}
.list-1 {
position: absolute;
left: 0px;
}
.list-2 {
position: absolute;
left: 100px;
}
.list-3 {
position: absolute;
left: 200px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27454848535453554657671309110917">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<ul class="nav nav-pills ">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu">
<ul class="list-1">
<li class="option-1">option 1</li>
<li class="option-2">option 2</li>
</ul>
<ul class="list-2">
<li>option 3</li>
<li>option 4</li>
</ul>
<ul class="list-3">
<li>option 5</li>
<li>option 6</li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a
>
<div class="dropdown-menu">
<ul class="list-1">
<li class="option-1">option 1</li>
<li class="option-2">option 2</li>
</ul>
<ul class="list-2">
<li>option 3</li>
<li>option 4</li>
</ul>
<ul class="list-3">
<li>option 5</li>
<li>option 6</li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a
class="nav-link dropdown-toggle"
data-toggle="dropdown"
href="#"
role="button"
aria-haspopup="true"
aria-expanded="false"
>Dropdown</a
>
<div class="dropdown-menu">
<ul class="list-1">
<li class="option-1">option 1</li>
<li class="option-2">option 2</li>
</ul>
<ul class="list-2">
<li>option 3</li>
<li>option 4</li>
</ul>
<ul class="list-3">
<li>option 5</li>
<li>option 6</li>
</ul>
</div>
</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="482a27273c3b3c3a2938087c667e6678">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>