简体   繁体   English

更改“ li”内“ a”标签的颜色

[英]Change the color of “a” tag inside of “li”

I've tried to do it by css, using: 我已经尝试通过CSS使用以下方法:

#mainmenu ul li:hover a
{
  color: #000000;
}

But it is not working, then i tried using jQuery, with: 但是它不起作用,然后我尝试使用jQuery,并带有:

function change()
{
  $(this).find('a').css('color','#000000');
}

Calling onMouseOver inside the <li> , but it is also not working... <li>内调用onMouseOver,但是它也不起作用...

Any idea? 任何想法?

尝试使用color: black !important ,如果可行,则寻找覆盖它的样式并重新组织代码。

The CSS code posted works when tested with the simplest possible HTML like 通过最简单的HTML进行测试后,发布的CSS代码可以正常工作

<div id=mainmenu>
<ul><li><a href=foo>link</ul>
</div>

and with no other style sheet used. 并且不使用其他样式表。 This means that in your real page, there is either some error in HTML syntax or, more probably, some other style sheet rule that overrides this rule. 这意味着在您的真实页面中,HTML语法中可能有错误,或者更有可能是其他样式表规则覆盖了该规则。

Thus, you should analyze and modify the style sheets. 因此,您应该分析和修改样式表。 If you need further help, you should post minimal code that still exhibits the problem. 如果您需要进一步的帮助,则应发布仍然存在问题的最少代码。

Using !important can be useful in making sure that it's not an HTML problem or typo in CSS code, but !important should rarely be used on live pages, especially in cases where you don't really know how your style sheets work together. 使用!important可以确保它不是CSS代码中的HTML问题或拼写错误,但!important很少用于实时页面,尤其是在您不太了解样式表如何协同工作的情况下。

Just try hovering 只是尝试悬停

#mainmenu ul li a:hover
{
  color: #000000;
}

我认为CSS可以解决您的问题,如果您想使用jquery来解决,则可以使用此链接Jquery Hyperlink插件

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

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