javascript - 有一个与主导航齐平的二级子菜单
问题描述
现在,当您将鼠标悬停在 Offices > New York 上时,您会注意到嵌套导航子菜单与“New York”选项齐平,上面有一些空白区域。
是否有一种 css 方法来删除这个空白,以便嵌套导航子菜单与顶部主导航齐平?“信息”选项就在“芝加哥”旁边。显示信息、预约会议、推荐的菜单。
还是javascript需要参与
.third-level-menu
{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu > li
{
height: 30px;
background: #999999;
}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}
/* Menu Link Styles */
.top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
<ul class="top-level-menu">
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li>
<a href="#">Offices</a>
<ul class="second-level-menu">
<li><a href="#">Chicago</a></li>
<li><a href="#">Los Angeles</a></li>
<li>
<a href="#">New York</a>
<ul class="third-level-menu">
<li><a href="#">Information</a></li>
<li><a href="#">Book a Meeting</a></li>
<li><a href="#">Testimonials</a></li>
<li><a href="#">Jobs</a></li>
</ul>
</li>
<li><a href="#">Seattle</a></li>
</ul>
</li>
<li><a href="#">Contact</a></li>
</ul>
解决方案
如果您relative
从 中删除该位置.second-level-menu li
,它将对第一级进行第三级引用。
.third-level-menu
{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu > li
{
height: 30px;
background: #999999;
}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.second-level-menu > li
{
height: 30px;
background: #999999;
}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}
/* Menu Link Styles */
.top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
<ul class="top-level-menu">
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li>
<a href="#">Offices</a>
<ul class="second-level-menu">
<li><a href="#">Chicago</a></li>
<li><a href="#">Los Angeles</a></li>
<li>
<a href="#">New York</a>
<ul class="third-level-menu">
<li><a href="#">Information</a></li>
<li><a href="#">Book a Meeting</a></li>
<li><a href="#">Testimonials</a></li>
<li><a href="#">Jobs</a></li>
</ul>
</li>
<li><a href="#">Seattle</a></li>
</ul>
</li>
<li><a href="#">Contact</a></li>
</ul>
推荐阅读
- scope - 如何更改 BigQuery 范围?
- python - Python 基于 argparse 选择方法
- python - 导入模块时不了解此 KeyError 的原因
- pandas - 来自云托管的 jupyter 的 pandas.read_clipboard?
- r - purrr::map() 不适用于 ordinal::nominal_test
- linux - 如何在 sed 中的给定行下方插入多行,其中行包含斜杠
- raspberry-pi - Raspberry Pi,插入第二条 FTDI 电缆时丢失 /dev/ttyUSB0
- perl - 你如何使for循环每次递增1
- jenkins - Jenkins Pipeline 中的“脚本”块外的动态并行阶段
- lua - 使用转义(魔术)字符作为 Lua 模式中字符范围的边界