I have an absolutely positioned Bootstrap 3 dropdown mega menu that is offsetting it's position from a static parent div. I want it to position itself to a relative parent that's further up the DOM.
I've tried using !important rules to set every parent (but the correct one) to position: static - but this won't work.
This doesn't have the correct visuals, but this CodePen demonstrates the issue:
https://codepen.io/anon/pen/mNEyVR
.site-header {
box-sizing: border-box;
color: rgb(51, 51, 51);
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
height: 150.15px;
line-height: 22.85px;
position: relative;
-moz-osx-font-smoothing: grayscale;
}
.site-header__main {
border-bottom-color: rgb(236, 236, 236);
border-bottom-style: solid;
border-bottom-width: 1px;
box-sizing: border-box;
color: rgb(51, 51, 51);
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
height: 85px;
line-height: 22.85px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
position: relative;
-moz-osx-font-smoothing: grayscale;
}
.site-header__main-inner {
background-attachment: scroll;
background-clip: border-box;
background-color: rgb(255, 255, 255);
background-image: none;
background-origin: padding-box;
background-position: 0% 0%;
background-position-x: 0%;
background-position-y: 0%;
background-repeat: repeat;
background-size: auto;
box-sizing: border-box;
color: rgb(51, 51, 51);
display: flex;
flex-direction: row;
flex-wrap: nowrap;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
height: 68px;
line-height: 22.85px;
margin-bottom: 16px;
margin-left: 0px;
margin-right: 0px;
margin-top: 16px;
padding-bottom: 0px;
padding-left: 40px;
padding-right: 40px;
padding-top: 0px;
position: relative;
z-index: 999;
-moz-box-direction: normal;
-moz-box-orient: horizontal;
-moz-osx-font-smoothing: grayscale;
}
.site-nav {
background-attachment: scroll;
background-clip: border-box;
background-color: rgba(0, 0, 0, 0);
background-image: none;
background-origin: padding-box;
background-position: 0% 0%;
background-position-x: 0%;
background-position-y: 0%;
background-repeat: repeat;
background-size: auto;
border-top-color: rgb(51, 51, 51);
border-top-style: none;
border-top-width: 0px;
box-sizing: border-box;
color: rgb(51, 51, 51);
flex-basis: 0px;
flex-grow: 1;
flex-shrink: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
height: 68px;
left: 0px;
line-height: 22.85px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
overflow: visible;
overflow-x: visible;
overflow-y: visible;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
position: static;
top: 0px;
transform: matrix(1, 0, 0, 1, 0, 0);
transition-delay: 0s, 0s, 0s;
transition-duration: 0.36s, 0.36s, 0.36s;
transition-property: transform, visibility, transform;
transition-timing-function: ease, ease, ease;
visibility: visible;
width: 1015px;
z-index: auto;
-moz-box-flex: 1;
-moz-osx-font-smoothing: grayscale;
}
nav {
box-sizing: border-box;
color: rgb(51, 51, 51);
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 22.85px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
visibility: visible;
-moz-osx-font-smoothing: grayscale;
}
ul {
box-sizing: border-box;
color: rgb(51, 51, 51);
display: flex;
float: left;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
justify-content: flex-end;
line-height: 22.85px;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
visibility: visible;
width: 1015px;
-moz-box-pack: end;
-moz-osx-font-smoothing: grayscale;
}
li.open {
box-sizing: border-box;
color: rgb(51, 51, 51);
display: block;
float: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 22.85px;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
position: static;
visibility: visible;
-moz-osx-font-smoothing: grayscale;
}
.dropdown-menu {
background-attachment: scroll;
background-clip: border-box;
background-color: rgb(236, 236, 236);
background-image: none;
background-origin: padding-box;
background-position: 0% 0%;
background-position-x: 0%;
background-position-y: 0%;
background-repeat: repeat;
background-size: auto;
border-bottom-color: rgb(214, 214, 214);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-image-outset: 0;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(51, 51, 51);
border-left-style: none;
border-left-width: 0px;
border-right-color: rgb(51, 51, 51);
border-right-style: none;
border-right-width: 0px;
border-top-color: rgb(51, 51, 51);
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-top-style: none;
border-top-width: 0px;
box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;
box-sizing: border-box;
color: rgb(51, 51, 51);
display: none;
float: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
left: 0px;
line-height: 22.85px;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
min-width: 160px;
padding-bottom: 32px;
padding-left: 0px;
padding-right: 0px;
padding-top: 16px;
position: absolute;
text-align: left;
top: 100%;
visibility: visible;
width: 100%;
z-index: 1000;
-moz-osx-font-smoothing: grayscale;
}
li.open .dropdown-menu {
background-attachment: scroll;
background-clip: border-box;
background-color: rgb(236, 236, 236);
background-image: none;
background-origin: padding-box;
background-position: 0% 0%;
background-position-x: 0%;
background-position-y: 0%;
background-repeat: repeat;
background-size: auto;
border-bottom-color: rgb(214, 214, 214);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-image-outset: 0;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(51, 51, 51);
border-left-style: none;
border-left-width: 0px;
border-right-color: rgb(51, 51, 51);
border-right-style: none;
border-right-width: 0px;
border-top-color: rgb(51, 51, 51);
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-top-style: none;
border-top-width: 0px;
box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;
box-sizing: border-box;
color: rgb(51, 51, 51);
display: block;
float: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
left: 0px;
line-height: 22.85px;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
min-width: 160px;
padding-bottom: 32px;
padding-left: 0px;
padding-right: 0px;
padding-top: 16px;
position: absolute;
text-align: left;
top: 68px;
visibility: visible;
width: 1015px;
z-index: 1000;
-moz-osx-font-smoothing: grayscale;
}
<header class="site-header">
<div class="site-header__main">
<div class="site-header__main-inner">
<div class="site-nav">
<nav>
<ul>
<li class="open">
<a href="#">Link 1</a>
<div class="dropdown-menu">
<p>content 1</p>
</div>
</li>
<li>
<a href="#">Link 2</a>
<div class="dropdown-menu">
<p>content 2</p>
</div>
</li>
<li>
<a href="#">Link 3</a>
<div class="dropdown-menu">
<p>content 3</p>
</div>
</li>
</ul>
</nav>
</div>
</div>
</div>
</header>
If you Inspect the first .dropdown-menu in Firefox, you'll see in the Layout tab that the menu is positioning itself in relation to a static parent.
It should be positioning in relation to a further-up parent that actually has its position set to relative.