gpt4 book ai didi

javascript - 尝试使用 HTML5 和 CSS 创建子菜单

转载 作者:行者123 更新时间:2023-11-28 08:12:44 25 4
gpt4 key购买 nike

我已经为此苦苦挣扎了几天,尽管我会向互联网寻求帮助。我想创建一个子菜单,当我将鼠标悬停在链接上时会出现该子菜单。这部分以时尚的方式工作,但是当链接出现在网页上时,它们是完全未格式化的。如果有任何帮助或建议,我将不胜感激。

这是 Fiddle

提前致谢。


HTML代码

<body>

<nav>
<ul><li><a href="index.html">home</a></li>

<li><a href="#">venue</a>
<ul class="hidden"> <li><a href="venue.html">address</a></li>
<li><a href="venue.html#background">venue background</a></li>
<li><a href="venue.html#instructors">instructors</a></li></ul> </li>

<li><a href="wakeboarding.html">wakeboarding</a>
<ul class="hidden"> <li><a href="wakeboarding.html">background</a></li>
<li><a href="wakeboarding.html">future</a></li></ul> </li>

<li><a href="events.html">up-coming events</a>
<ul class="hidden"> <li><a href="events.html">professional</a></li>
<li><a href="events.html">amateur</a></li> </ul></li>

<li><a href="prices.html">prices</a>
<ul class="hidden"> <li><a href="prices.html">prices</a></li>
<li><a href="events.html">special offers</a></li></ul> </li>

<li><a href="contact.html">contact us</a></li></ul>
</nav>

<img src = "logo.png"
alt = "Logo" />

<form>
<input type="email" required placeholder="sign up for newsletter" /> <input type="submit" value="submit">
</form>

</body>
<br />

CSS 代码

body nav > ul >  li {

list-style-type: none;
position: intial;
top: 110px;
//right: -200px;
display: inline;

}

body nav > ul .hidden {


opacity: 1;
position: relative;

}

body nav > ul > li:hover >.hidden {

visibility: visible;
display:block;
position:absolute;
top:10x;

}



body nav ul li {

display: inline;
padding: 80px;
font-family: Geneva,Tahoma,Verdana,sans-serif;
font-size: 24px;

}

最佳答案

如果对你有帮助,看看这个

https://jsfiddle.net/Edrees21/ae55p7u1/2/

<div class="nav">
<ul>
<li class="main-menu-item">
<a class="link">Link 1</a>
<ul class="sub-menu">
<li>Sub menu 1</li>
<li>Sub menu 2</li>
<li>Sub menu 3</li>
</ul>
</li>
<li class="main-menu-item">
<a class="link">Link 2</a>
<ul class="sub-menu">
<li>Sub menu 1</li>
<li>Sub menu 2</li>
</ul>
</li>
<li class="main-menu-item">
<a class="link">Link 3</a>
<ul class="sub-menu">
<li>Sub menu 1</li>
<li>Sub menu 2</li>
</ul>
</li>
</ul>
</div>

CSS ul { 列表样式:无; margin :0; 填充:0;

li {
padding: 5px;
}

.main-menu-item {
position: relative;
cursor: pointer;
}

.main-menu-item:hover > ul {
display: block;
}

.sub-menu {
display: none;
position: absolute;
left: 80px;
top: 0;
}

关于javascript - 尝试使用 HTML5 和 CSS 创建子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29169111/

25 4 0
文章推荐: c++ - LNK1120 关于使用 lineSetAppPriorityW
文章推荐: css - 将网页作为一个整体缩放到任何分辨率
文章推荐: c# - 设置
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com