我有一个粘性的主菜单与选项卡“类别”下拉菜单“categoriesDropdown”,当我将鼠标悬停在它上面。我如何中心div到身体不是它的父母
我需要下拉菜单具有屏幕的宽度,并且是 在屏幕的中心。
我需要下拉菜单来粘贴到主菜单的底部。
唯一的问题是,我似乎无法将下拉菜单居中。我只能把它放在相对于父div(类别) 我使用的代码显示在下面。
<div class="categories">
<a>Categories</a>
<div id="categoriesDropdown"></div>
</div>
CSS
.categories {
padding-left: 20px;
padding-right: 20px;
height: 45px;
display: inline-block;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#categoriesDropdown {
position: absolute;
background: #1d1d1d;
width: 100vw;
height: 0px;
z-index: -1;
overflow: auto;
}
#categoriesDropdown.show {
height: 500px;
}
编辑:发生这种情况时,我尝试左:0;正确:0; the grey square being the drop down menu
如果我理解正确的你应该做的就是把左:0,右:0在您的#categories下降到cen如果需要,可以使用顶部:0和底部:0垂直居中如果需要 – Benneb10
将它居中在类别div的中间。我的问题是我如何将它集中在身体中央。 – hermanboy07