CSS下拉菜单主选项卡 [英] CSS drop down menu main tab snag

查看:115
本文介绍了CSS下拉菜单主选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在建立一个CSS下拉菜单,我有一个轻微的障碍,想知道是否有人可以帮助我解决这个问题。我有一个包含此HTML的菜单

I have been building a CSS drop down menu and I have a slight snag and wondered if anyone could help me fix this. I have a menu that has this HTML

<div id="menu">
<ul>
<li><a class="active" href="#">Home</a>
<ul class="sub-menu">
<li><a href="#">This is sub</a></li>
<li><a href="#">sub menu item</a></li>
<li><a href="#">This is a long sub menu item</a></li>
</ul>
</li>  
<li><a href="#">Location</a></li>
<li><a href="#">another link</a></li>
</ul>
</div>

目前当我悬停在< li> 'Home'它的宽度扩展了很多,我想要适应我有的子类菜单。如何阻止这种情况发生?要实现类似:

Currently when I hover over the main <li> 'Home' it's width expands a lot, I think to accommodate the sub-class menus that I have. How can I stop this from occurring? To achieve something like:

|首页| // Nice short main tab

|子菜单链接|

|另一个子菜单链接|

|Home| // Nice short main tab
|A sub menu link |
|Another sub menu link|

反对这是目前发生的(原谅我的图的粗糙)

As opposed to this that is currently happening (forgive the crudeness of my diagram)

|首页.................. .. | //真的很麻烦所有标签

|子菜单链接|

|另一个子菜单链接|

|Home....................| // really long messing up everything tab
|A sub menu link |
|Another sub menu link|

这是我的菜单的CSS代码:

This is my CSS code for the menu:

#menu ul {
margin: 0;
list-style: none;
padding: 0 0 0 20px;
position: relative;
z-index: 40;
}
#menu ul li {
float: left;
padding: 10px 10px 13px 0;
position: relative;
z-index: 50;
}
#menu li a {
text-decoration: none;
font-family: Verdana, Geneva, sans-serif;


推荐答案

我有基本相同的标记,所以下面的代码应该

I have basically the same markup so the following code should work well for what you need.

我留下了所有的颜色和图片信息,以备您需要帮助。

I left all of the color and image info in case you needed help there too.

#menu {
    background: none repeat scroll 0 0 #333333;
    border: 0 none;
    font: bold 14px "Lucida Sans Unicode","Bitstream Vera Sans","Trebuchet Unicode MS","Lucida Grande",Verdana,Helvetica,sans-serif;
    margin: 0;
    padding: 0;
    width: 100%;
}
#menu ul {
    background: none repeat scroll 0 0 #333333;
    height: 35px;
    list-style: none outside none;
    margin: 0 0 3px;
    padding: 0;
    width: 100%;
}
#menu li {
    float: left;
    padding: 0;
}
#menu li a {
    background: no-repeat scroll right bottom #333333;
    color: #CCCCCC;
    display: block;
    font-weight: normal;
    line-height: 35px;
    margin: 0;
    padding: 0 10px;
    text-align: center;
    text-decoration: none;
}
#menu li a:hover, #menu ul li:hover a {
    background: no-repeat scroll center bottom #2580A2;
    color: #FFFFFF;
    text-decoration: none;
}
#menu li ul {
    background: none repeat scroll 0 0 #333333;
    border: 0 none;
    display: none;
    height: auto;
    margin: 0;
    padding: 0;
    position: absolute;
    width: 225px;
    z-index: 200;
}
#menu li:hover ul {
    display: block;
}
#menu li li {
    display: block;
    float: none;
    margin: 0;
    padding: 0;
    width: 225px;
}
#menu li:hover li a {
    background: none repeat scroll 0 0 transparent;
}
#menu li ul a {
    display: block;
    font-size: 12px;
    font-style: normal;
    height: 35px;
    margin: 0;
    padding: 0 10px 0 15px;
    text-align: left;
}
#menu li ul a:hover, #menu li ul li:hover a {
    background: no-repeat scroll left center #2580A2;
    border: 0 none;
    color: #FFFFFF;
    text-decoration: none;
}

这篇关于CSS下拉菜单主选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆