CSS 下拉菜单问题

发布于 2024-08-27 19:34:05 字数 3776 浏览 3 评论 0原文

我的导航中的 css 下拉菜单有一个小问题。产品导航选项卡应该有下拉菜单。此外,导航工作正常,但子类别似乎无法正确显示。

这里是链接

这是我的导航代码:

HTML

<div id="nav">
    <ul id="navlist">
        <li><a href="home.html" id="nav-home">Home</a></li>
        <li><a href="company.html" id="nav-company">company</a></li>
        <li><a href="benefits.html" id="nav-benefits">benefits</a></li>
        <li><div id="nav-products2">Products</div>
            <ul>
                <li><a href="food.html" id="nav-food-serv">Food Processing Services</a></li>
                <li><a href="vehicle.html" id="nav-vehicle-serv">Vehicle Services</a></li>
                <li><a href="auto.html" id="nav-auto-serv">Automotive Services</a></li>
                <li><a href="laundry.html" id="nav-laundry-serv">Automotive Services</a></li>
            </ul>
        </li>
        <li><a href="laboratories.html" id="nav-labs">laboratories</a></li>
        <li><a href="industries.html" id="nav-industries">industries</a></li>
        <li><a href="contact.html" id="nav-contact">contact</a></li>
    </ul>
</div>

CSS

#nav {
float:left;
width:1002px;
height:42px;
}
#navlist {
list-style: none;
list-style-position:outside;
list-style-type: none;
}
#navlist li{
float:left;
}
#navlist li a {
display: block; 
height: 42px; 
overflow: hidden; 
background-position: top left; 
background-repeat: no-repeat;   
text-indent: -999em;
}
#navlist li a:hover {
background-position: bottom left;
}
#navlist li .current {background-position: bottom left;}

/* NAV SPECIFICS */
#nav-home {width: 129px; background-image: url(../images/nav/home.jpg);}
#nav-company {width: 161px; background-image: url(../images/nav/company.jpg);}
#nav-benefits {width: 133px; background-image: url(../images/nav/benefits.jpg);}
#nav-products {width: 112px; background-image: url(../images/nav/products.jpg);}
#nav-labs {width: 137px; background-image: url(../images/nav/laboratories.jpg);}
#nav-industries {width: 169px; background-image: url(../images/nav/industries.jpg);}
#nav-contact {width: 161px; background-image: url(../images/nav/contact.jpg);}

#nav-food-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-vehicle-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-auto-serv {width: 161px; background-image: url(../images/nav/nav/sub.jpg);}
#nav-laundry-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-products2 {width: 112px; background-image: url(../images   /nav/products.jpg);height: 42px; overflow: hidden; background-position: top left;   background-repeat: no-repeat;text-indent: -999em;}
#nav-products2:hover {background-position: bottom left;}

#navlist li ul { /* second-level lists */
position: absolute;
z-index:10;
list-style:none;
display: block;
background: #000;
width: 161px;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
margin:0;
padding:0;
border-left:1px solid #a58545;
border-right:1px solid #a58545;
}
#navlist li ul li {
list-style:none;
display: block;
clear:left;
width:100%;
 }
#navlist li ul li a {
display:block;
overflow: hidden;
height:42px;
background-position: top left;
background-repeat: no-repeat;
text-indent: -999em;
margin:0;
background-color:0;
padding:0;
width: 161px;
 }
#navlist li ul li a:hover {
background-position: bottom left;
}

Im having a little issue with the css drop down in my navigation. The products nav tab is suppose to have the drop down. Additionally, the nav works fine but it seems that the sub categories arent displaying correctly.

HERE IS LINK

Here is my navigation code:

HTML

<div id="nav">
    <ul id="navlist">
        <li><a href="home.html" id="nav-home">Home</a></li>
        <li><a href="company.html" id="nav-company">company</a></li>
        <li><a href="benefits.html" id="nav-benefits">benefits</a></li>
        <li><div id="nav-products2">Products</div>
            <ul>
                <li><a href="food.html" id="nav-food-serv">Food Processing Services</a></li>
                <li><a href="vehicle.html" id="nav-vehicle-serv">Vehicle Services</a></li>
                <li><a href="auto.html" id="nav-auto-serv">Automotive Services</a></li>
                <li><a href="laundry.html" id="nav-laundry-serv">Automotive Services</a></li>
            </ul>
        </li>
        <li><a href="laboratories.html" id="nav-labs">laboratories</a></li>
        <li><a href="industries.html" id="nav-industries">industries</a></li>
        <li><a href="contact.html" id="nav-contact">contact</a></li>
    </ul>
</div>

CSS

#nav {
float:left;
width:1002px;
height:42px;
}
#navlist {
list-style: none;
list-style-position:outside;
list-style-type: none;
}
#navlist li{
float:left;
}
#navlist li a {
display: block; 
height: 42px; 
overflow: hidden; 
background-position: top left; 
background-repeat: no-repeat;   
text-indent: -999em;
}
#navlist li a:hover {
background-position: bottom left;
}
#navlist li .current {background-position: bottom left;}

/* NAV SPECIFICS */
#nav-home {width: 129px; background-image: url(../images/nav/home.jpg);}
#nav-company {width: 161px; background-image: url(../images/nav/company.jpg);}
#nav-benefits {width: 133px; background-image: url(../images/nav/benefits.jpg);}
#nav-products {width: 112px; background-image: url(../images/nav/products.jpg);}
#nav-labs {width: 137px; background-image: url(../images/nav/laboratories.jpg);}
#nav-industries {width: 169px; background-image: url(../images/nav/industries.jpg);}
#nav-contact {width: 161px; background-image: url(../images/nav/contact.jpg);}

#nav-food-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-vehicle-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-auto-serv {width: 161px; background-image: url(../images/nav/nav/sub.jpg);}
#nav-laundry-serv {width: 161px; background-image: url(../images/nav/sub.jpg);}
#nav-products2 {width: 112px; background-image: url(../images   /nav/products.jpg);height: 42px; overflow: hidden; background-position: top left;   background-repeat: no-repeat;text-indent: -999em;}
#nav-products2:hover {background-position: bottom left;}

#navlist li ul { /* second-level lists */
position: absolute;
z-index:10;
list-style:none;
display: block;
background: #000;
width: 161px;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
margin:0;
padding:0;
border-left:1px solid #a58545;
border-right:1px solid #a58545;
}
#navlist li ul li {
list-style:none;
display: block;
clear:left;
width:100%;
 }
#navlist li ul li a {
display:block;
overflow: hidden;
height:42px;
background-position: top left;
background-repeat: no-repeat;
text-indent: -999em;
margin:0;
background-color:0;
padding:0;
width: 161px;
 }
#navlist li ul li a:hover {
background-position: bottom left;
}

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

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

发布评论

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

评论(1

不念旧人 2024-09-03 19:34:05

仅使用 css,您需要将鼠标悬停时定位到 li,而不是其中的 div

为了显示包含的 ul,您必须更改它的 left

像这样的东西:

li:hover ul {
    left: 0;
}

With just css you will need target the li on hover, not the div in it.

And for the containing ul to show up, you will have to change it´s left.

Something like:

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