0

我在每个下拉菜单项的整个宽度上的悬停效果都有一些问题。我希望每个项目的背景颜色发生变化。目前,我只能获得悬停文本的宽度,而不是下拉列表的宽度。

http://jsfiddle.net/7AXZR/

谢谢!

的HTML:

<div id="nav">

<ul>
    <li><img src="images/kranz3.png" alt="kranz"/><a href="compete.php" id="competenav">COMPETE</a></li>
    <li><img src="images/thumb3.png" alt="thumb"/><a href="score.php" id="scorenav">SCORE</a></li>
    <div id="logolist"><li><a href="index.php"><img src="images/logorz.png" width="175em" /></a></li></div>
    <li><img src="images/shopnav.png" alt="bag"/><a href="shop.php" id="shopnav">SHOP</a></li>
    <ul id="more-dropdown"><li><img src="images/morenav2.png" alt="more"/><a href="#" id="morenav">MORE</a><ul>
        <div id="dropdown-links">
        <li><a href="printyourown.php">Print your own art</a></li>
        <li><a href="compete.php">How it works</a></li>
        <li><a href="causes.php">About Causes</a></li>
        <li><a href="#">About our products</a></li>
        <li><a href="#">About us</a></li>
        <li><a href="#">Help & Feedback</a></li>
        <li><a href="termsofservice.php">Terms of Service</a></li>
        <li><a href="#">Privacy</a></li></ul>
        </div>
    </li>
</ul>
</div>
<div class="clear">
</div>

CSS:

#nav {
    position:relative;
    background:#ffffff;
    width:100%;
    height:0.2em:
    overflow:visible;
    margin-top:-2em;
    font-family:Cusmyrb;
    font-size:75%;

}

#logolist {
    position:absolute;
    padding-top:2em;
    width:150px;
    left:50%;
    margin-left:-90px;
    margin-top:-7%;

}


#nav ul {
    list-style-type:none;

}

#nav li {
    display:inline;
    float:left;
    width:20%;
    margin-left:2%;
    margin-right:2%;
    margin-top:3%;
    text-align:center;
}



#nav a {
    display:block;
    margin-right:0% auto;
    padding-left:0% auto;
    color:#343234;
    text-decoration:none;


}

#nav a:hover {
 color:#5020B8;
}

#nav a:active {
 color:#5020B8;
}

.clear {
    clear:both;
}

#more-dropdown {
    margin: 0;
    padding: 0;
    height:0;
}

#more-dropdown li {
    list-style: none;
    float: left;
}



#dropdown-links li a {
    float:left;
    display: block;
    font-family:Cusmyr;
    font-size:14px;
    background-color:#797A7D;
    color:#797A7D;
    text-decoration: none;
    margin-top:0.5em;
    margin-left:1em;
}

    #dropdown-links li a:hover {
    float:left;
    display: block;
    font-family:Cusmyr;
    font-size:14px;
    background-color:#01A07E;
    color:#797A7D;
    text-decoration: none;
    margin-top:0.5em;
    margin-left:1em;
}

    #more-dropdown li ul {
    display: none; 
    width: 6em; /* Width to help Opera out */
    background-color:#797A7D;
    border:1px solid white;
}

    #more-dropdown li:hover ul {
    display: block;
    position: absolute;
    margin: 0;
    padding: 0; }
#more-dropdown li:hover li {
    float: none;
    background-color:#01A07E;
}
#more-dropdown li:hover li a {
    color: #ffffff;
}
#more-dropdown li li a:hover { 
}
4

1 回答 1

1

转变

#nav a:hover

#nav:hover a

编辑:首先:<a>元素中的<li>元素具有顶部和左侧边距,因此它们不会填满整个列表项

第二:#nav li选择器也适用于下拉列表中的列表项,您不希望它们浮动。这是因为周围的列表项的高度为 0

除了第一个列表项外,我删除了浮动:

新小提琴:http: //jsfiddle.net/PZGLz/

于 2013-03-18T22:54:29.397 回答