gpt4 book ai didi

html - 使 HTML/CSS 下拉菜单适应多级

转载 作者:搜寻专家 更新时间:2023-10-31 19:27:24 25 4
gpt4 key购买 nike

我一直在努力使我正在处理的网站的原始下拉菜单变成多级。我所有的尝试都失败了(。出于某种原因,我只能做“margin-right”来对齐元素,这会导致一些问题。我认为这与 position 属性有关。

这是我的 HTML:

<ol id="nav">
<li><a href="index.php">Home</a></li>
<li class="dropdown_alignedLeft">
<a href="">Products</a>
<ul><li class="dropdown_alignedRight">
<a href="">iPoP</a>
<ul style="margin-right:-400px; top:0px;-webkit-border-top-right-radius: 5px;border-top-right-radius: 5px;-moz-border-radius-topright: 5px;"><li><a href="customers.php?category=ipop">iPoP - Network Solutions for Vessels</a></li></ul><li class="dropdown_alignedRight">
<a href="">Cameras</a>
<ul style="margin-right:-400px; top:0px;-webkit-border-top-right-radius: 5px;border-top-right-radius: 5px;-moz-border-radius-topright: 5px;"><li><a href="customers.php?category=icam">iCam 501 Ultra - Intrinsically Safe Digital Camera with Flash</a></li></ul><li class="dropdown_alignedRight">
<a href="">BNWAS</a>
<ul style="margin-right:-400px; top:0px;-webkit-border-top-right-radius: 5px;border-top-right-radius: 5px;-moz-border-radius-topright: 5px;"><li><a href="customers.php?category=bnwas">BNWAS - Bridge Navigation Watch Alarm System</a></li></ul><li class="dropdown_alignedRight">
<a href="">Lighting</a>
<ul style="margin-right:-400px; top:0px;-webkit-border-top-right-radius: 5px;border-top-right-radius: 5px;-moz-border-radius-topright: 5px;"><li><a href="customers.php?category=peli">Peli 2690 - Intrinsically Safe LED Head Lamp</a></li></ul><li class="dropdown_alignedRight">
<a href="">Communication</a>
<ul style="margin-right:-400px; top:0px;-webkit-border-top-right-radius: 5px;border-top-right-radius: 5px;-moz-border-radius-topright: 5px;"><li><a href="customers.php?category=handy">Ex-Handy 06 - Intrinsically Safe Cell Phone</a></li></ul>
</ul>
<li class="dropdown_alignedLeft">
<a href="">Customers</a>
<ul>
<li><a href="customers.php?category=maritime">Maritime</a></li>
<li><a href="customers.php?category=non">Non-Maritime</a></li>
<li class="dropdown_lastItem"><a href="customers.php?category=organizations">Regulatory Organizations</a></li>
</ul>
<li><a href="order.php">Product Enquiry</a></li>
<li><a href="contact.php">Contact Us</a></li>
<li class="dropdown_alignedLeft">
<a href="">Company</a>
<ul>
<!-- <li><a href="">About Us</a></li> -->
<li><a href="newsandpr.php?category=News">News</a></li>
<li class="dropdown_lastItem"><a href="newsandpr.php?category=Press Release">Press Releases</a></li>
</ul>
</ol>

还有我的 CSS:

#nav {
float:right;
margin:15px 0 0;
}
#nav li {
float:left;
}
#nav li a {
display:block;
font-family:"PT Sans","Helvetica Neue",Arial,sans-serif;
font-size:16px;
text-decoration:none;
color:#2B95C8;
padding:10px 20px 20px;
}
.dropdown_alignedLeft,.dropdown_alignedRight {
position:relative;
}
#nav .dropdown_alignedLeft>a,#nav .dropdown_alignedRight>a {
background:url(../images/dropdown_arrow_blue.png) no-repeat top right;
padding:10px 30px 20px 20px;
}
#nav .dropdown_alignedLeft:hover>a,#nav .dropdown_alignedRight:hover>a {
-moz-border-radius-topleft:5px;
-moz-border-radius-topright:5px;
-moz-border-radius-bottomright:0;
-moz-border-radius-bottomleft:0;
-webkit-border-top-left-radius:5px;
-webkit-border-top-right-radius:5px;
-webkit-border-bottom-right-radius:0;
-webkit-border-bottom-left-radius:0;
border-top-left-radius:5px;
border-top-right-radius:5px;
border-bottom-right-radius:0;
border-bottom-left-radius:0;
color:#FFF;
background:#2378A1 url(../images/dropdown_arrow_blue.png) no-repeat bottom right;
}
.dropdown_alignedLeft ul,.dropdown_alignedRight ul {
display:none;
}
#nav .dropdown_alignedLeft:hover>ul,#nav .dropdown_alignedRight:hover>ul {
display:block;
z-index:100;
position:absolute;
top:50px;
-moz-border-radius-topleft:0;
-moz-border-radius-topright:0;
-moz-border-radius-bottomright:5px;
-moz-border-radius-bottomleft:5px;
-webkit-border-top-left-radius:0;
-webkit-border-top-right-radius:0;
-webkit-border-bottom-right-radius:5px;
-webkit-border-bottom-left-radius:5px;
border-top-left-radius:0;
border-top-right-radius:0;
border-bottom-right-radius:5px;
border-bottom-left-radius:5px;
background:#2378A1;
padding:0 0 6px;
}
#nav .dropdown_alignedRight:hover>ul {
top:50px;
right:0;
text-align:right;
}
#nav li ul li {
float:none;
border-bottom:1px dashed #2B95C8;
margin:0 20px;
}
#nav li ul li.dropdown_innerTitle {
border:none;
font-family:"Helvetica Neue",Arial,sans-serif;
font-size:15px;
white-space:nowrap;
color:#C8DDE7;
margin:10px 20px 0;
padding:10px 0;
}
#nav li ul li.dropdown_lastItem {
border:none;
}
#nav li ul li a {
font-family:"Helvetica Neue",Arial,sans-serif;
font-size:13px;
color:#FFF;
white-space:nowrap;
padding:10px 0 9px;
}
#nav>li:hover>a,#nav li .current_page {
color:#2378A1;
background:url(../images/current_page_arrow_blue.png) no-repeat center bottom;
}
#nav li ul li a:hover {
color: #C8DDE7;
}

要查看菜单的实时版本,请转到此处:

JSFiddle - Live Menu

最佳答案

您没有关闭很多 li 标签,您的子菜单只是从容器中飞出。清理了您的代码并进行了太多修改,无法在此处列出:

http://jsfiddle.net/MmHSd/4/

关于html - 使 HTML/CSS 下拉菜单适应多级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9791874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com