我有一个居中的第三级导航,显示在第二级悬停时显示。我想隐藏什么,直到它直接悬停在它上面?第三级居中菜单下拉导航问题
P.S. - 我知道代码会比较干净,就像我在网上看到的一样,但不知道如何清理它,所以我希望代码清晰。
谢谢!
JS小提琴:DEMO
#centeredmenu {
clear:both;
float:left;
margin:0 0 30px 0;
padding:0;
border-bottom:1px solid #000; /* black line below menu */
width:100%;
font-family:Arial, Helvetica, sans-serif; /* Menu font */
z-index:1000; /* This makes the dropdown menus appear above the page content below */
position:relative;
background-color: #000;
}
/* Top menu items */
#centeredmenu ul {
margin:0;
padding:0;
list-style:none;
float:right;
position:relative;
right:50%;
}
#centeredmenu ul li {
margin:0 0 0 1px;
padding:0;
float:left;
position:relative;
left:50%;
top:1px;
}
#centeredmenu ul li a {
display: block;
margin: 0;
padding: 10px 20px;
font-size: 1em;
line-height: 1em;
text-decoration: none;
color: #fff;
font-weight: bold;
border-bottom: 1px solid #000;
}
#centeredmenu ul li a:hover {
background: #a3c2df; /* Top menu items background color */
color: #fff;
border-bottom: 1px solid #03f;
}
#centeredmenu ul li:hover a {
background: #a3c2df; /* Top menu items background color */
color: #000;
border-bottom: 1px solid #03f;
}
/* 2nd Level Items */
#centeredmenu ul ul {
display:none; /* Submenus are hidden by default */
position:absolute;
left:0;
right:auto; /* Resets the right:50% on the parent ul */
width:12em; /* Width of the drop-down menus */
}
#centeredmenu ul ul li {
left:auto; /*Resets the left:50% on the parent li */
margin:0; /* Resets the 1px margin from the top menu */
clear:left;
width:100%;
}
/* 3rd Level Items */
#centeredmenu ul ul ul {
display:none; /* Submenus are hidden by default */
position:absolute;
top:0;
left:155px;
right:auto; /* Resets the right:50% on the parent ul */
width:12em; /* Width of the drop-down menus */
}
#centeredmenu ul ul ul li {
left:auto; /* Resets the left:50% on the parent li */
margin:0; /* Resets the 1px margin from the top menu */
clear:left;
width:100%;
}
#centeredmenu ul ul li a,
#centeredmenu ul li.active li a,
#centeredmenu ul li:hover ul li a {
font-size:0.9em;
font-weight:normal; /* Resets the bold set for the top level menu items */
background:#eee;
color:#444;
line-height:1.4em; /* Overwrite line-height value from top menu */
border-bottom:1px solid #ddd; /* Submenu item horizontal lines */
}
#centeredmenu ul ul li a:hover,
#centeredmenu ul li.active ul li a:hover,
#centeredmenu ul li:hover ul li a:hover {
background: #a3c2df; /* Submenu items background color */
color:#000; /* Submenu items hover color */
}
/* Flip the last 2nd menu so it stays within the page */
#centeredmenu ul ul.last {
left:auto; /* Resets left:0; value */
right:0; /* Set right value instead */
}
/* Make the 2nd menus appear on hover */
#centeredmenu ul li:hover ul {
display:block; /* Show the submenus */
}
/* Make the 3rd menus appear on hover */
#centeredmenu ul li:hover ul ul{
display:block; /* Show the submenus */
}
<div id="centeredmenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Documents</a>
<ul>
<li><a href="#">Reading</a></li>
<li><a href="#">Writing</a>
<ul>
<li><a href="#">Excerpt 1</a></li>
<li><a href="#">Excerpt 2</a></li>
<li><a href="#">Excerpt 3</a></li>
<li><a href="#">Excerpt 4</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
谢谢@ckuijjer的解释和说明。我一定会阅读该页面资源链接。令我感到困惑的是,我仍然放置了所有各种CSS组合,即ul.last,li:hover等。 大部分类的使用甚至更先进 - Codepen很好! – alondonb 2014-09-25 20:44:47