所以我使用css创建了一个导航菜单,我只有一个问题,当我将鼠标悬停在子菜单上时,我希望顶级菜单将字体颜色更改为白色,这样人们就知道哪个子菜单了正在观看...
<li style="width:150px" id="lovedating"><a href="#">Love & Dating</a>
<div id="love&dating" class="belownav">
<div class="ontop">Love & Dating</div>
<div class="navitem"><ul id="navitemul">
<li class="marright"><a href="http://www.curious-howto.com/love-dating/broken-hearths/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Broken-Hearths.jpg" width="63" height="40" /><span class="marleft">Broken Hearths</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/dating/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Dating.jpg" width="63" height="40" /><span class="marleft">Dating</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/dating-humor/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Dating-Humor.jpg" width="63" height="40" /><span class="marleft">General Health</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/flirting/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Flirting.jpg" width="63" height="40" /><span class="marleft">Flirting</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/kissing/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Kissing.jpg" width="63" height="40" /><span class="marleft">Kissing</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/physical-relationships/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/Physical-Relationships.jpg" width="63" height="40" /><span class="marleft">Physical Relationships</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/relationships/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/relationships.jpg" width="63" height="40" /><span class="marleft">Relationships</span></a></li>
<li class="marright"><a href="http://www.curious-howto.com/love-dating/weddings/"><img class="fl" src="http://www.curious-howto.com/images/2013/04/weddings.jpg" width="63" height="40" /><span class="marleft">Weddings</span></a></li>
</ul></div>
</div></li>
因此,我希望当我将鼠标悬停在子菜单ul#navitemul上时,李#被喜欢为字体颜色白色。这只能用css吗...我试过了:
ul#navitemul:hover li#lovedating a{color:white;}
但它没有效果,请指教:)谢谢
如果您想了解我所说的更多内容,请访问我的网站www.curious-howto.com并查看菜单:)
答案 0 :(得分:0)
我认为代码应该是
<ul id="navitemul">
<li style="width:150px" id="lovedating"><a href="#">Love & Dating</a>
</li> <!-- Close the <li> tag here -->
由于您的<li>
标记包含所有<div>
,因此该样式将继承
答案 1 :(得分:0)
我会尝试使用jQuery。
$('ul#navitemul').hover(function(){ // change color of the link to white
$(this).closest('#lovedating a').css('color', '#FFF');
},function(){ // change the color of the link back
$(this).closest('#lovedating a').css('color', '#009');
});