简体   繁体   English

悬停伪选择器未按预期工作

[英]Hover pseudo selector not working as expected

I have a list item with an anchor tag inside. 我有一个带有锚标签的列表项。

I want to add the hover pseudo selector to a list item and therefore the anchor tag inside it. 我想将悬停伪选择器添加到列表项,并在其中添加锚标记。

My goal is to change the colour of the anchor tag text when hovering over the list item . 我的目标是将鼠标悬停在列表项上时更改锚标记文本的颜色

li:hover{
    background-color: #000;
    color:#fff;
    width: 60px;
    color:#fff;
}

<li>
    <a href="#">one</a>
</li>

JSFIDDLE JSFIDDLE

It dosn't seem to work though, what am I doing wrong here? 它似乎没有用,我在这里做错了什么?

The selector that you're looking for is 您要寻找的选择器是

li:hover a {
  /* hover color here */
}

DEMO 演示

 a { color: green; } li:hover a { color: red; } 
 <ul> <li> <a href="#">one</a> </li> <li> <a href="#">two</a> </li> <li> <a href="#">three</a> </li> <li> <a href="#">four</a> </li> <li> <a href="#">five</a> </li> </ul> 

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

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