HTML CSS下拉菜单 [英] html css dropdown menu
问题描述
这是我第一次发布Stack Overflow,并且我并不熟悉发布论坛规则。所以请让我知道我做错了什么。我在论坛上研究过这个问题,我遇到的问题都没有给我一个明确的答案。
我试图从News元素创建一个下拉菜单,但运行代码时我从来没有看到任何可见的结果。我试图将 .dropdown-content
的显示
值更改为 block
看看它是否会使列表可见,但没有显示。我缺少什么?
< div id =nav>< ul style =list-style-type:noneid =menu> < li>< a href =home.html>主页< / a>< / li> < li class =dropdown>< a class =dropbtnhref =#>新闻< / a> < div class =dropdown-content> < a href =#>游戏< / a> < a href =#>网页设计< / a> < a href =#>旅游< / a> < / DIV> < /锂> <! - 为联系人信息创建指向同一页面部分的链接 - > < li>< a href =#bottom>联络资讯< / a>< / li> < i href =login.html>登录< / a>< / li>< / ul>< / div>
解决方案
您可以将位置:fixed;
添加到 #nav
并更改 #menu
from width:80%;
to width:100%;
以下是 JS小提琴。
希望有所帮助!
This is my first ever post to Stack Overflow and I'm not familiar with forum regulations with posting. So please let me know anything that I have done wrong. I have researched this issue in the forums and nothing I've come across gives me a clear answer.
I am trying to create a dropdown menu from the "News" element, but I never get any visible result when running the code. I tried to change the .dropdown-content
's display
value to block
to see if it would make the list visible, but nothing showed. What am I missing?
body{
background-image: url("images/seamless-panda-bear-pattern.jpg");
font-size: 100%;
width: 80%;
margin: auto;
font-family: Palatino,"Palatino", Arial;
}
#top{
background-color: black;
color: white;
padding-left: 10px;
border: 2px solid white;
font-family: Copperplate,"Copperplate Gothic Light",fantasy;
opacity: 0.85;
padding-left: 25px;
}
#menu{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed;
width: 80%;
}
li{
float: left;
}
#login{
float: right;
padding-right: 20px;
}
li a{
display: block;
color: white;
text-decoration: none;
text-align: center;
padding: 14px 16px;
}
li a:hover{
background-color: white;
color: black;
}
li.dropdown{
display: inline-block;
}
.dropdown-content{
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0,2);
padding: 12px 16px;
z-index: 1;
}
.dropdown-content a{
display: block;
text-decoration: none;
padding: 12px 16px;
color: black;
}
.dropdown:hover .dropdown-content{
display: block;
}
#bio{
}
#bottom{
}
<div id="nav">
<ul style="list-style-type: none" id="menu">
<li><a href="home.html">Home</a></li>
<li class="dropdown"><a class="dropbtn" href="#">News</a>
<div class="dropdown-content">
<a href="#">Games</a>
<a href="#">Web Design</a>
<a href="#">Travel</a>
</div>
</li>
<!-- create a link to a part of the same page for contact info -->
<li><a href="#bottom">Contact info</a></li>
<li id="login"><a href="login.html">Log In</a></li>
</ul>
</div>
To solve your position fixed issue. You can add position: fixed;
to #nav
and change the width on #menu
from width: 80%;
to width: 100%;
Here's a JS Fiddle.
Hope that helped!
这篇关于HTML CSS下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!