简体   繁体   English

悬停效果不会更改锚链接的颜色

[英]Hover effect not changing color of anchor link

I have a menu which is supposed to change the color of the anchor link on hovering over the li but the problem is that the hover effect only works when I hover over the anchor link. 我有一个菜单,应该在将鼠标悬停在li上时更改锚定链接的颜色,但是问题是,只有当我将鼠标悬停在锚定链接上时,悬停效果才会起作用。

<div style="background-color:#FFFFFF" id="menu" class="menu">
  <ul class="links">

    <li><a href="news-265.html" class="active">News &amp; Views</a> » </li>

    <li><a href="facts-269.html">Quick Facts </a>  </li>

    <li><a href="media-releases-268.html">Media Releases</a>  </li>

    <li><a href="gallery-270.html">Photo Gallery</a>  </li>

    <li><a href="social-media-271.html">Social Media Channels</a>  </li>

    <li><a href="contacts-272.html">Media Contacts </a>  </li>
  </ul>
</div>


body {
  font-family: 'Raleway', sans-serif;
}

#menu a {
  color:#76b900;
}

#menu li:hover {
  background:#76b900;
  color:#FFFFFF;
  text-decoration:none;
}

#menu a:hover {
  background:#76b900;
  color:#FFFFFF;
  text-decoration:none;
}

#menu li {
  padding: 12px 0 13px 10px; 
  border-bottom: none;  
}

Here is a link to my JSBin. 这是我的JSBin的链接

You could get rid of the hover over the list element, change the anchor display to block, and then only hover the anchor. 您可以摆脱将鼠标悬停在list元素上,将锚点显示更改为“ block”,然后仅将锚点悬停在上面。

HERE is a fiddle. 这里是一个小提琴。

You can then play with the css of the anchor to get the size of the block. 然后,您可以使用锚点的CSS来获得块的大小。

#menu a {
  display: block;
  color:#76b900;
  width: 200px;
  text-decoration: none;
}

you can use this 你可以用这个

#menu li:hover > a 
{
color:#FFFFFF;
}
#menu a {
  color:#76b900;
  text-decoration:none;
}

#menu li:hover {
  background:#76b900;
  color:#ffffff;

}

#menu li:hover a {
 color:#ffffff;
}

尝试#menu li:hover a代替#menu a:hover

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM