鼠标悬停子菜单损坏

发布于 2024-09-15 22:20:57 字数 2934 浏览 7 评论 0原文

我的网站上有一个鼠标悬停子菜单运行得非常好(事实上它在 Chrome、IE 7 & 8 和 FF 中运行得非常好),但现在它不知何故被破坏了,我看不到问题。

这是 CSS:

.MainMenu {
    width: 90% !important;
    min-width: 800px;
    height: 42px !important;
    padding: 0 0 0 10%;
    overflow: hidden;
    border-top: 1px solid #0054a6;
    border-bottom: 1px solid #0054a6;
    background: transparent url("Images/ServiceMenuBG.png");
    background-repeat: repeat-x;
}
.MainMenu ul {
    padding: 0;
    margin:0;
    list-style: none;
}
.MainMenu li {
    float: left;
    position: relative;
    height: 31px;
    width: 150px;
    padding: 11px 0 0 0;
    text-align: center;
    border-right: 1px solid #0054a6;
}
.MainMenuItem#First { border-left: 1px solid #0054a6; }
.MainMenuItem a {
    color: #ffffff;
    display: block;
    height: 31px;
    width: 150px;
    font-weight: bold;
    text-decoration: none;
}
.MainMenuItem:hover { background: transparent url("Images/ServiceMenuBG.png") repeat-x 0 -42px; }
.SubMenu {
    z-index: 500;
    display: none;
    width: 150px !important;
    position: absolute;
    top: 10px;
    left: 0;
    background-color: rgb(51,118,184);
}
.SubMenu li { padding: 0 0 2px 5px; height: 20px !important; width: 143px; }
.SubMenu li a {
    height: 20px !important;
    font-weight: normal;
    color: #ffffff;
    text-align: left;
    text-decoration: none;
}
.SubMenu li a:hover { text-decoration: underline; }
.MainMenu li.MainMenuItem>ul { top: auto; left: auto; }
.MainMenu li.MainMenuItem:hover ul { display: block; }'

这是 HTML:

<div class="MainMenu">
    <ul>
        <li class="MainMenuItem" id="First"><a href="~/Default.aspx">Home</a></li>
        <li class="MainMenuItem"><a href="Pages/Philosophies.aspx">Philosophies</a></li>
        <li class="MainMenuItem"><a href="Pages/Services.aspx#top">Services</a>
            <ul class="SubMenu">
                <li id="TopItem"><a href="Pages/Services.aspx#shop">Shop Repair</a></li>
                <li><a href="Pages/Services.aspx#donations">Donations</a></li>
                <li><a href="Pages/Services.aspx#consulting">Consulting</a></li>
                <li id="BottomItem"><a href="Pages/Services.aspx#on-site">On-site Service</a></li>
            </ul>
        </li>
        <li class="MainMenuItem"><a href="Pages/Contracts.aspx">Contracts</a></li>
        <li class="MainMenuItem"><a href="Pages/AboutUs.aspx">About Us</a></li>
        <li class="MainMenuItem"><a href="Pages/ContactUs.aspx">Contact Us</a></li>
    </ul>
</div>

子菜单在鼠标悬停时或我将其初始 display 属性设置为 block 时都不会显示。就好像它根本不存在于页面上一样。

预先感谢您的任何帮助。

I had a mouseover submenu working very nicely on my site (so nicely in fact that it was working exactly right in Chrome, IE 7 & 8, and FF), but now it's broken somehow and I can't see the problem.

Here's the CSS:

.MainMenu {
    width: 90% !important;
    min-width: 800px;
    height: 42px !important;
    padding: 0 0 0 10%;
    overflow: hidden;
    border-top: 1px solid #0054a6;
    border-bottom: 1px solid #0054a6;
    background: transparent url("Images/ServiceMenuBG.png");
    background-repeat: repeat-x;
}
.MainMenu ul {
    padding: 0;
    margin:0;
    list-style: none;
}
.MainMenu li {
    float: left;
    position: relative;
    height: 31px;
    width: 150px;
    padding: 11px 0 0 0;
    text-align: center;
    border-right: 1px solid #0054a6;
}
.MainMenuItem#First { border-left: 1px solid #0054a6; }
.MainMenuItem a {
    color: #ffffff;
    display: block;
    height: 31px;
    width: 150px;
    font-weight: bold;
    text-decoration: none;
}
.MainMenuItem:hover { background: transparent url("Images/ServiceMenuBG.png") repeat-x 0 -42px; }
.SubMenu {
    z-index: 500;
    display: none;
    width: 150px !important;
    position: absolute;
    top: 10px;
    left: 0;
    background-color: rgb(51,118,184);
}
.SubMenu li { padding: 0 0 2px 5px; height: 20px !important; width: 143px; }
.SubMenu li a {
    height: 20px !important;
    font-weight: normal;
    color: #ffffff;
    text-align: left;
    text-decoration: none;
}
.SubMenu li a:hover { text-decoration: underline; }
.MainMenu li.MainMenuItem>ul { top: auto; left: auto; }
.MainMenu li.MainMenuItem:hover ul { display: block; }'

Here's the HTML:

<div class="MainMenu">
    <ul>
        <li class="MainMenuItem" id="First"><a href="~/Default.aspx">Home</a></li>
        <li class="MainMenuItem"><a href="Pages/Philosophies.aspx">Philosophies</a></li>
        <li class="MainMenuItem"><a href="Pages/Services.aspx#top">Services</a>
            <ul class="SubMenu">
                <li id="TopItem"><a href="Pages/Services.aspx#shop">Shop Repair</a></li>
                <li><a href="Pages/Services.aspx#donations">Donations</a></li>
                <li><a href="Pages/Services.aspx#consulting">Consulting</a></li>
                <li id="BottomItem"><a href="Pages/Services.aspx#on-site">On-site Service</a></li>
            </ul>
        </li>
        <li class="MainMenuItem"><a href="Pages/Contracts.aspx">Contracts</a></li>
        <li class="MainMenuItem"><a href="Pages/AboutUs.aspx">About Us</a></li>
        <li class="MainMenuItem"><a href="Pages/ContactUs.aspx">Contact Us</a></li>
    </ul>
</div>

The SubMenu doesn't display either on mouseover or if I set it's initial display property to block. It's as if it doesn't exist on the page at all.

Thanks in advance for any help.

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

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

发布评论

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

评论(1

ˉ厌 2024-09-22 22:20:57
.MainMenu { overflow: hidden; }

隐藏了子菜单,因此删除该行。 CSS 中的第 6 行。

正如 Sotiris 提到的,

.MainMenuItem a { color: #ffffff; }

隐藏了顶部菜单项(可能不在您的版本上,因为我看到您有背景图像)

.MainMenu { overflow: hidden; }

is hiding the sub menus, so remove that line. Line 6 in your CSS.

As Sotiris mentioned

.MainMenuItem a { color: #ffffff; }

hides the top menu items (maybe not on your version because I see you have a background image)

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