[英]how to change icon on hover css
So I have a default icon and I want it to be able to light up active on hover. 因此,我有一个默认图标,希望它能够在悬停时亮起。 For some reason I cannot get this to work, and i'd like to use css if possible.
由于某些原因,我无法使它正常工作,并且如果可能的话,我想使用CSS。 thx
谢谢
HTML HTML
<ul class='nav nav-main nav-sidebar'>
<li role='presentation'>
<a href='javascript:void(0)'>
<i class='pull-left fu fu-lg fu-parents'></i>
Parents
</a>
CSS CSS
li {
.hidden-on-hover {
display: inherit;
}
.visible-on-hover {
display: none;
}
}
li:hover {
.hidden-on-hover {
display: none;
}
.visible-on-hover {
display: inherit;
}
i.fu.fu-parents {
background: image_url("icons/navigation/default/parents.svg") center center no-repeat;
background-size: contain
}
i.fu.fu-parents.active {
background: image_url("icons/navigation/active/parents-active.svg") center center no-repeat;
background-size: contain
}
}
You aren't applying your styles on :hover
您没有在
:hover
上应用样式
https://developer.mozilla.org/en-US/docs/Web/CSS/%3Ahover https://developer.mozilla.org/en-US/docs/Web/CSS/%3Ahover
i.fu.fu-parents:hover {
background: image_url("icons/navigation/active/parents-active.svg");
}
Do that and you should get the desired behavior. 这样做,您应该获得所需的行为。
Also do yourself a favor and learn some more about HTML/CSS. 也请帮自己一个忙,并进一步了解HTML / CSS。 You should not be using a
<ul>
for a nav and you have way more classnames than necessary. 您不应该在导航中使用
<ul>
,并且类名的数量超出了必要。 These things will make your site more difficult to maintain and require additional work such as your role=presentation
to support screen readers. 这些都会使您的网站更难以维护,并且需要进行其他工作,例如您的
role=presentation
以支持屏幕阅读器。 Here is an online course that's free and will teach you solid basics: https://dash.generalassemb.ly/ 这是一个免费的在线课程,将教您扎实的基础知识: https : //dash.generalassemb.ly/
I think you are going for an effect like this JSFiddle ? 我认为您要实现类似JSFiddle的效果?
a {color: red;}
ul{list-style-type: none;}
a:hover > i {color: blue;}
I couldnt figure it out with css, I know there is a way but I used jquery instead. 我无法用css弄清楚,我知道有办法,但是我改用了jquery。 Because my images had two classes, one default and one active.
因为我的图像有两类,所以一类是默认类,另一类是活动类。 thx
谢谢
$("i").hover(
function () {
$(this).addClass('active');
},
function () {
$(this).removeClass('active');
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.