请转至:my website这里。然后将鼠标悬停在“GCSE”上,然后悬停在“数学”上。您会看到,当您将鼠标悬停在数学或地理上时,会出现另一个“子菜单”,其中包含下拉内容“代数”等。我正在尝试使子菜单与父菜单水平内联。
这是子菜单的CSS代码:
/*-------------- Second sub menu -----------*/
.dropdown2 {
float: left;
overflow: hidden;
}
.dropdown2 .dropbtn2 {
font-size: 20px;
border: none;
outline: none;
color: white;
padding: 20px 20px;
height: 120px;
box-sizing: border-box;
background-color: inherit;
}
/*--- Colour when hovered over ---*/
.redhover a:hover,
.dropdown2:hover .dropbtn2 {
background-color: #ddd;
}
/* --- Colour of background of box when parent is hovered over but sub content is NOT hovered over --- */
.dropdown-content2 {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
margin-left: 160px;
}
/* --- Text formatting of sub-content --- */
.dropdown-content2 a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
font-family: 'Montserrat';
}
/*--- Colour of background box when hovering over sub content ----*/
.dropdown-content2 a:hover {
background-color: #ddd;
}
/*----- affects size of sub content block ---*/
.dropdown2:hover .dropdown-content2 {
display: block;
}
/*-----------End of sub menu -------------*/
哪一行,是当前设置“下拉内容”的行,例如代数等“低于” parent ?查看我的代码,我不确定我是如何设法让我的下拉内容显示在按钮下方的。
如果我能弄清楚是什么让它出现在父级下方,我应该能够弄清楚如何将它水平内联移动。我已经将下拉内容移动到父级“右侧”的正确距离,但它设置在下面。
干杯!
最佳答案
将 -44px
的 margin-top 值
添加到 dropdown-content2
将实现此目的,尽管它可能不是最有效的解决方案.
.dropdown-content2 {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
margin-left: 160px;
margin-top: -44px;
}
关于javascript - 试图理解我自己的一行关于导航栏的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838463/