gpt4 book ai didi

jquery - 尝试在现有导航栏上添加下拉项

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:24 24 4
gpt4 key购买 nike

我正在尝试向我的“元素”菜单项添加下拉功能,如 [第 1/2/3 页] 所示。有没有一种有效的方法来做到这一点? (如果适用,欢迎使用 jQuery 解决方案)

DEMO

(出于某种原因,Projects 元素在 JSFiddle 中被拉伸(stretch)了,但无论如何它仍然有效)

<html>
<header id="header">
<div class="container">
<img src="<!--logo-->"/>
<nav id="nav">
<ul>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li><a href="#">Projects</a>
<ul>
<li><a href="page1.html">Page 1</a></li>
<li><a href="page2.html">Page 2</a></li>
<li><a href="page3.html">Page 3</a></li>
</ul>
</li>
<li>
<a href="contact.html">Contact</a>
</li>
</ul>
</nav>
</div>
</header>
</html>

1 :

最佳答案

使用 ul ul { display: none; 隐藏嵌套菜单} 并触发隐藏/嵌套的 ulli:hover > ul { display: block;

.container {
position: relative;
margin: 0 auto;
width: 94%;
max-width: 1100px;
font-family: helvetica, sans-serif;
}

#nav {
position: absolute;
right: 0;
top: -15px;
height: 60px;
text-transform: uppercase;
font-weight: bold;
}

#nav ul li {
float: left;
list-style: none;
}

#nav ul li a {
display: block;
color: white;
text-decoration: none;
padding: 0 10px;
}

#header {
z-index: 2;
position: fixed;
width: 100%;
height: 60px;
line-height: 60px;
background: #222;
color: white;
}

#header img {
width: 180px;
height: 60px;
}

#header h1 {
top: 0px;
margin: 0px;
font-size: 1.75em;
}


/* unvisited link */

a:link {
color: blue;
}


/* visited link */

a:visited {
color: purple;
}


/* mouse over link - Nav*/

#nav a:hover {
color: black;
background-color: gold;
}


/* mouse over link - regular*/

.back a:hover {
color: blue;
}


/* selected link */

a:active {
color: blue;
}

ul ul {
display: none;
position: absolute;
background: #222;
padding: 0;
}

#nav ul ul li {
float: none;
}

li:hover > ul {
display: block;
}
<header id="header">
<div class="container">
<img src="<!--logo-->" alt="logo placeholder" />
<nav id="nav">
<ul>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li><a href="#">Projects</a>
<ul>
<li><a href="page1.html">Page 1</a>
<li><a href="page2.html">Page 2</a></li>
<li><a href="page3.html">Page 3</a></li>
</ul>
</li>
<li>
<a href="contact.html">Contact</a>
</li>
</ul>
</nav>
</div>
</header>

关于jquery - 尝试在现有导航栏上添加下拉项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42708602/

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