CSS 垂直菜单与水平子菜单
我知道这是一个很常见的问题,但我一直很难找到这个问题的确切答案。
我想要的菜单是由点组成的。这些点是垂直的。这些点的文本将在稍后添加,所以现在不要介意。我想要其中一些点的子菜单。该子菜单应该是水平的。最好用下面的例子来说明。
x
x x x
x
x
x
但现在它看起来像这样:
x
x
xx
x
x
所以子菜单位于它应该位于另一个项目顶部的下方一行。希望这是清楚的
我的 html 是:
<ul id="mainmenu">
<li id="liHome" class="active">
<a href="#item-x1y1" class="panel" rel="none" id="Home">Home</a>
</li>
<li id="liServices" class=" ">
<a href="#item-x1y2" class="panel" rel="SubMenuY2" id="Services">Services</a>
<ul style="" id="SubMenuY2" class="submenu">
<li><a href="#">Sub-item 1</a></li>
<li><a href="#">Sub-item 2</a></li>
</ul>
</li>
<li id="liEnvironment">
<a href="#item-x1y3" class="panel" rel="none" id="Environment">Environment</a>
</li>
<li id="liCareer">
<a href="#item-x1y4" class="panel" rel="none" id="Career">Career</a>
</li>
<li id="liContact">
<a href="#item-x1y5" class="panel" rel="none" id="Contact">Contact</a>
</li>
</ul
css 是:
#mainmenu {
position: fixed;
left: 20px;
top: 50%;
z-index: 999999;
margin-top:-200px;
}
#mainmenu li {
height: 40px;
position: relative;
}
#mainmenu a {
display: block;
width: 40px;
height: 40px;
background: url(Images/dotnav.png) 0 100% no-repeat;
text-indent: -10000px;
overflow: hidden;
}
#mainmenu a:hover,
#mainmenu li.active a {
background-position: 0 0;
}
.submenu
{
list-style-type: none;
position:relative;
float:left;
}
.submenu li
{
display: inline;
float:left;
position:relative
}
I know this is a quite frequent question, but I've been having troubles finding the exact answer to this problem.
The menu I want is consists of dots. These dots are vertical. The text for these dots will be added later, so don't mind that now. I want a submenu to some of these dots. This submenu should be horizontal. Best illustrated by the below.
x
x x x
x
x
x
But for now it looks like this:
x
x
xx
x
x
So the sub menu is one row below where it should on top of another item. Hope this is clear
The html I have is:
<ul id="mainmenu">
<li id="liHome" class="active">
<a href="#item-x1y1" class="panel" rel="none" id="Home">Home</a>
</li>
<li id="liServices" class=" ">
<a href="#item-x1y2" class="panel" rel="SubMenuY2" id="Services">Services</a>
<ul style="" id="SubMenuY2" class="submenu">
<li><a href="#">Sub-item 1</a></li>
<li><a href="#">Sub-item 2</a></li>
</ul>
</li>
<li id="liEnvironment">
<a href="#item-x1y3" class="panel" rel="none" id="Environment">Environment</a>
</li>
<li id="liCareer">
<a href="#item-x1y4" class="panel" rel="none" id="Career">Career</a>
</li>
<li id="liContact">
<a href="#item-x1y5" class="panel" rel="none" id="Contact">Contact</a>
</li>
</ul
And the css is:
#mainmenu {
position: fixed;
left: 20px;
top: 50%;
z-index: 999999;
margin-top:-200px;
}
#mainmenu li {
height: 40px;
position: relative;
}
#mainmenu a {
display: block;
width: 40px;
height: 40px;
background: url(Images/dotnav.png) 0 100% no-repeat;
text-indent: -10000px;
overflow: hidden;
}
#mainmenu a:hover,
#mainmenu li.active a {
background-position: 0 0;
}
.submenu
{
list-style-type: none;
position:relative;
float:left;
}
.submenu li
{
display: inline;
float:left;
position:relative
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我删除了一些样式内容并保留了定位内容,以便更清晰:
我还添加了一些代码来处理鼠标悬停。
I stripped some of your styling stuff and left the positioning stuff so it's clearer:
I also added some code to handle the mouse hovers.