简体   繁体   English

悬停不适用于li css的背景

[英]hover doesn't apply background to li css

What's wrong with my :hover below? 我有什么问题:在下面盘旋? I dosen't seem to have effect. 我似乎没有效果。 Tried overflow hidden but it doesn't appear any effect. 尝试溢出隐藏但它没有出现任何影响。

.tabs-nav li:hover {

}

demo https://jsfiddle.net/tpd83jxx/ 演示https://jsfiddle.net/tpd83jxx/

You have to apply the :hover effect in a:hover because you have already applied background-color to a element. 您必须在:hover中应用:悬停效果,因为您已经将背景颜色应用于元素。 Try and add this code. 尝试并添加此代码。

.tabs-nav a:hover {
  background-color: red;
}

Nothing wrong with the css ,Here you applied background for a tag. 没有错css ,在这里,你应用backgrounda标签。

So change the hover to a 所以将悬停更改a

.tabs-nav li:hover a {
    color: white;
    background: red;
} 

Below code works for me 下面的代码适合我

.tabs-nav li :hover {
  color: white;
  background: red;
}

If I am not wrong Space is added to apply hover to the child of li. 如果我没有错,则添加空格以将hover应用于li的子项。 In this case for anchor tag 在这种情况下为锚标签

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

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