我有一个由 HTML 和 CSS 组成的菜单,我正在尝试获取它,以便一旦用户将鼠标悬停在菜单中的子级别项目上,div info1 将出现在菜单的右侧。理想情况下,如果可能的话,我想用 HTML 和 CSS 来做这件事,但如果有一个更简单的 jQuery 或 JavaScript 修复,那也可以。我当然会感谢您的帮助。
这是HTML:
<body>
<div id="navigation">
<nav>
<ul class="top-level">
<li><a href="#">Top-level Item</a>
<ul class="sub-level">
<li><a href="#">Sub-level Item</a></li>
<li><a href="#">Sub-level Item</a></li>
<li><a href="#">Sub-level Item</a></li>
</ul>
</li>
<li><a href="#">Top-level Item</a>
<ul class="sub-level">
<li><a href="#">Sub-level Item</a>
<li><a href="#">Sub-level Item</a></li>
<li><a href="#">Sub-level Item</a></li>
<li><a href="#">Sub-level Item</a></li>
</ul>
</li>
</nav>
</div>
<div ID="info1">
<center><img src="image.jpg" border="0" height=170 width=250 ></center><br><center><table BORDER=4 CELLPADDING=6 ><tr><td><br>I want this div to display on the right side of the screen once the mouse has hovered over a sub-level menu item.<br><br></td></tr></table></center>
</div>
</body>
这是CSS:
#navigation
{
width: 200px;
font-size: 0.75em;
}
#navigation ul
{
margin: 0px;
padding: 0px;
}
#navigation li
{
list-style: none;
}
ul.top-level li
{
border-bottom: #fff solid;
border-top: #fff solid;
border-width: 1px;
}
#navigation a
{
color: #fff;
cursor: pointer;
display:block;
height:25px;
line-height: 25px;
text-indent: 10px;
text-decoration:none;
width:100%;
}
#navigation li:hover
{
background: #f90;
position: relative;
}
ul.sub-level
{
display: none;
}
li:hover .sub-level
{
background: #999;
border: #fff solid;
border-width: 1px;
display: block;
position: absolute;
left: 200px;
top: -1px;
}
ul.sub-level li
{
border: none;
float:left;
width:200px;
}
#info1
{
font-family: "Verdana,Arial,Helvetica";
size: -1;
display: none;
}
*/ I thought this might work*/
li:hover .top-level li:hover .sub-level + #info1
{
display: block;
}