HTML 和CSS 多层下拉菜单,需要悬停着色帮助
这是列表和项目:
<ul>
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">Forums</a>
<ul>
<li>
<a href="#">Baseball</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Basketball</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Football</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Hockey</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
这是 CSS:
ul
{
margin: 0;
padding: 0;
list-style: none;
width: 100px;
border-bottom: 1px solid #ccc;
}
a
{
color: #777;
}
a:hover
{
background-color: #fff;
}
ul li
{
position: relative;
}
li ul
{
display: inline;
position: absolute;
left: 99px;
top: 0;
display: none;
}
li ul li ul
{
width: 150px;
}
ul li a
{
display: block;
text-decoration: none;
background: #bad8f8;
padding: 2px 0 2px 10px;
border: 1px solid #ccc;
border-bottom: 0;
}
li:hover > ul
{
display: block;
}
我想要发生的是,当我将鼠标悬停在论坛上时,它会突出显示白色。然后,如果我查看篮球,论坛和篮球会突出显示为白色。对于孩子来说也是如此。我希望能够显示一条路径,这样当他们越过某些东西时,虽然定位应该能够告诉他们正在访问哪条路径,但我希望突出显示以使其清晰。任何帮助将不胜感激。哦,如果可能的话,请不要使用 JavaScript。谢谢。
当我将鼠标悬停在最后一个孩子上时,这就是现在的样子:
我也想将红色圆圈突出显示为白色。
更新
这是我必须接受的。就目前而言,它很丑陋,但这是我能想到的最好的。
Here's the list and items:
<ul>
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">Forums</a>
<ul>
<li>
<a href="#">Baseball</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Basketball</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Football</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
<li>
<a href="#">Hockey</a>
<ul>
<li>
<a href="#">Trading</a>
</li>
<li>
<a href="#">Personal Collections</a>
</li>
<li>
<a href="#">Box Breaks</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Here's the CSS:
ul
{
margin: 0;
padding: 0;
list-style: none;
width: 100px;
border-bottom: 1px solid #ccc;
}
a
{
color: #777;
}
a:hover
{
background-color: #fff;
}
ul li
{
position: relative;
}
li ul
{
display: inline;
position: absolute;
left: 99px;
top: 0;
display: none;
}
li ul li ul
{
width: 150px;
}
ul li a
{
display: block;
text-decoration: none;
background: #bad8f8;
padding: 2px 0 2px 10px;
border: 1px solid #ccc;
border-bottom: 0;
}
li:hover > ul
{
display: block;
}
What I want to happen is when I hover over Forums, it highlight white. Then if I go over Basketball, Forum and Basketball are highlighted white. And the same goes for the children. I want to be able to show a path so when they over over something, while positioning should be able to tell them which one they're accessing, I want the highlighting to make it clear. Any help would be appreciated. Oh, and please no Javascript if possible. Thanks.
This is what it looks like now when I hover over the last child:
And the red circled ones I also want to be highlighted white.
Update
This is what I'm going to have to accept. It's ugly, for now, but that's the best I can come up with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 CSS 中,当您向下导航嵌套 ul 列表时,将父级保持在“选定”状态可能是不可能的。我不认为 CSS 选择器能够向上提升树。不过,使用 javascript 应该不难。这是一个参考:
活动子级的父级的复杂CSS选择器
鲍勃
Keeping the parent in the 'selected' state as you navigate down the nested ul lists probably is not possible in CSS. I don't think CSS selectors are able to ascend up the tree. This should not be difficult using javascript though. Here is a reference:
Complex CSS selector for parent of active child
Bob