HTML 和CSS 多层下拉菜单,需要悬停着色帮助

发布于 2024-10-13 09:23:52 字数 3478 浏览 6 评论 0原文

这是列表和项目:

<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。谢谢。

当我将鼠标悬停在最后一个孩子上时,这就是现在的样子: alt text

我也想将红色圆圈突出显示为白色。 alt text

更新
这是我必须接受的。就目前而言,它很丑陋,但这是我能想到的最好的。 替代文本

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:
alt text

And the red circled ones I also want to be highlighted white.
alt text

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.
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-10-20 09:23:52

在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文