CSS 水平下拉菜单定位
我正在尝试使用水平下拉菜单实现水平导航菜单。我试图弄清楚如何将水平下拉文本居中,使其位于导航容器的中心,这样用户就不必将鼠标移动到最左侧即可到达链接。
<style type="text/css">
#nav-container {
padding: 4px;
width: 900px;
height: 60px;
background: #CCC;
}
#navbar {
margin:0;
padding:0;
}
#navbar li {
padding: 6px;
display: inline;
list-style: none;
}
#navbar li ul {
display: none;
position: absolute;
margin:0;
padding:0;
width: 900px;
}
#navbar li:hover ul {
display: block;
}
</style>
</head>
<body>
<div id="nav-container">
<ul id="navbar">
<li><a href="#">Link</a>
<ul>
<li><a href="#">Hello</a></li>
<li><a href="#">World</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Peace</a></li>
<li><a href="#">Love</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Smiles</a></li>
<li><a href="#">Cries</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Homer</a></li>
<li><a href="#">Peter</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Giggity</a></li>
<li><a href="#">Fapping</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Napster</a></li>
<li><a href="#">Myspace</a></li>
</ul>
</li>
</ul>
</div>
这是粗略的代码,只是为了展示一个示例,这是代码的实时示例。
谢谢
I am trying to implement a horizontal navigation menu with a horizontal dropdown menu. I am trying to figure out how to center the horizontal dropdown text so it sits in the center of the navigation container so the user doesn't have to move the mouse far left to reach the links.
<style type="text/css">
#nav-container {
padding: 4px;
width: 900px;
height: 60px;
background: #CCC;
}
#navbar {
margin:0;
padding:0;
}
#navbar li {
padding: 6px;
display: inline;
list-style: none;
}
#navbar li ul {
display: none;
position: absolute;
margin:0;
padding:0;
width: 900px;
}
#navbar li:hover ul {
display: block;
}
</style>
</head>
<body>
<div id="nav-container">
<ul id="navbar">
<li><a href="#">Link</a>
<ul>
<li><a href="#">Hello</a></li>
<li><a href="#">World</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Peace</a></li>
<li><a href="#">Love</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Smiles</a></li>
<li><a href="#">Cries</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Homer</a></li>
<li><a href="#">Peter</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Giggity</a></li>
<li><a href="#">Fapping</a></li>
</ul>
</li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Napster</a></li>
<li><a href="#">Myspace</a></li>
</ul>
</li>
</ul>
</div>
This is rough code just to show an example, here is a live example of the code.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相对和绝对定位的组合应该可以解决问题。我尝试添加这两条规则,这似乎有效:
这似乎可以解决问题。
A combination of relative-absolute positioning should do the trick. I tried adding these two rules and that seemed to work:
That seems to do the trick.