简体   繁体   English

悬停时更改链接中文本的颜色

[英]Changing the color of a text in a link on hover

I have the following html and css: http://jsfiddle.net/5hX6S/ 我有以下html和CSS: http : //jsfiddle.net/5hX6S/

The idea is to have a list of items which are links and then when the user scrolls over the list item it lights up in a different color and the color of the text inside changes to white. 这个想法是要有一个链接的项目列表,然后当用户在列表项目上滚动时,它会以不同的颜色点亮,并且内部文本的颜色变为白色。

You can see how it all looks in the jsfiddle above, my problem is that the whole item's background does change into orange but the text does not. 您可以在上面的jsfiddle中看到所有外观,我的问题是整个项目的背景确实变成了橙色,但文本却没有。 The text only changes if you scroll directly above it, which is not enough. 仅当您直接在文本上方滚动时,文本才会更改,这还不够。 I'd also like to make the whole list a link, not just the text inside of it. 我还想使整个列表成为一个链接,而不仅仅是其中的文本。

I tried putting a div, span, nothing inside of the list and moving that class that you see around using the following css: 我尝试将div,span,任何内容都不放在列表中,并使用以下css移动您看到的类:

.side_menu_link:hover {
    background: #ff7200;
    color: #fff !important;
}

But nothing works. 但是什么都行不通。 The only thing that succeeded so far was moving the 'a' tags outside of the 'li' tags but as far as I'm concerned that's not the right way to do it syntax wise. 到目前为止,唯一成功的方法是将'a'标签移到'li'标签之外,但就我而言,这不是正确执行语法的正确方法。 So any suggestions? 有什么建议吗?

Are you trying to have the hover effect on the link? 您是否要在链接上产生悬停效果? Or the list itself? 还是列表本身? If you want the link to change color on hover then in your CSS have 如果您希望链接在悬停时更改颜色,则在CSS中

 .side_menu_link a:hover { 
    color: color;
    }

etc. 等等

Here you are 这个给你

http://jsfiddle.net/iamnotsam/5hX6S/4/ http://jsfiddle.net/iamnotsam/5hX6S/4/

You needed to replace this 您需要更换它

a:hover {
    text-decoration: none;
    color: #fff;
}

with this

#left_menu ul li:hover a {
    text-decoration: none;
    color: #fff;
}

You want 你要

.side_menu_link:hover a { ... }
                     ^^^--- note this

instead, so that the new background color applies ONLY to the <a> tag, not the entire <div class="side_menu_link"> . 代替,以使新的背景颜色适用于<a>标签,而不是整个<div class="side_menu_link">

 a:hover{color:red;background:green} 
 <a href="#">Home</a> 

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

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